comp AP gateway: message conversion:
Convert direct AP items to XMPP `<message>` stanzas, and vice versa. Documentation will follow soon to explain the behaviour. rel 366
This commit is contained in:
parent
72ec311ef1
commit
fa81d96d79
1 changed files with 252 additions and 85 deletions
|
|
@ -612,6 +612,43 @@ class SatXMPPEntity(core_types.SatXMPPEntity):
|
|||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def send(self, obj):
|
||||
# original send method accept string
|
||||
# but we restrict to domish.Element to make trigger treatments easier
|
||||
assert isinstance(obj, domish.Element)
|
||||
# XXX: this trigger is the last one before sending stanza on wire
|
||||
# it is intended for things like end 2 end encryption.
|
||||
# *DO NOT* cancel (i.e. return False) without very good reason
|
||||
# (out of band transmission for instance).
|
||||
# e2e should have a priority of 0 here, and out of band transmission
|
||||
# a lower priority
|
||||
# FIXME: trigger not used yet, can be uncommented when e2e full stanza
|
||||
# encryption is implemented
|
||||
# if not self.host_app.trigger.point("send", self, obj):
|
||||
# return
|
||||
super().send(obj)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def sendMessageData(self, mess_data):
|
||||
"""Convenient method to send message data to stream
|
||||
|
||||
This method will send mess_data[u'xml'] to stream, but a trigger is there
|
||||
The trigger can't be cancelled, it's a good place for e2e encryption which
|
||||
don't handle full stanza encryption
|
||||
This trigger can return a Deferred (it's an asyncPoint)
|
||||
@param mess_data(dict): message data as constructed by onMessage workflow
|
||||
@return (dict): mess_data (so it can be used in a deferred chain)
|
||||
"""
|
||||
# XXX: This is the last trigger before u"send" (last but one globally)
|
||||
# for sending message.
|
||||
# This is intented for e2e encryption which doesn't do full stanza
|
||||
# encryption (e.g. OTR)
|
||||
# This trigger point can't cancel the method
|
||||
yield self.host_app.trigger.asyncPoint("sendMessageData", self, mess_data,
|
||||
triggers_no_cancel=True)
|
||||
self.send(mess_data["xml"])
|
||||
defer.returnValue(mess_data)
|
||||
|
||||
def sendMessage(
|
||||
self, to_jid, message, subject=None, mess_type="auto", extra=None, uid=None,
|
||||
no_trigger=False):
|
||||
|
|
@ -659,8 +696,7 @@ class SatXMPPEntity(core_types.SatXMPPEntity):
|
|||
# we try to guess the type
|
||||
if data["subject"]:
|
||||
data["type"] = C.MESS_TYPE_NORMAL
|
||||
elif not data["to"].resource: # if to JID has a resource,
|
||||
# the type is not 'groupchat'
|
||||
elif not data["to"].resource:
|
||||
# we may have a groupchat message, we check if the we know this jid
|
||||
try:
|
||||
entity_type = self.host_app.memory.getEntityDatum(
|
||||
|
|
@ -675,8 +711,7 @@ class SatXMPPEntity(core_types.SatXMPPEntity):
|
|||
else:
|
||||
data["type"] = C.MESS_TYPE_CHAT
|
||||
else:
|
||||
data["type"] == C.MESS_TYPE_CHAT
|
||||
data["type"] == C.MESS_TYPE_CHAT if data["subject"] else C.MESS_TYPE_NORMAL
|
||||
data["type"] = C.MESS_TYPE_CHAT
|
||||
|
||||
# FIXME: send_only is used by libervia's OTR plugin to avoid
|
||||
# the triggers from frontend, and no_trigger do the same
|
||||
|
|
@ -895,43 +930,6 @@ class SatXMPPClient(SatXMPPEntity, wokkel_client.XMPPClient):
|
|||
)
|
||||
post_xml_treatments.addCallback(self.messageSendToBridge)
|
||||
|
||||
def send(self, obj):
|
||||
# original send method accept string
|
||||
# but we restrict to domish.Element to make trigger treatments easier
|
||||
assert isinstance(obj, domish.Element)
|
||||
# XXX: this trigger is the last one before sending stanza on wire
|
||||
# it is intended for things like end 2 end encryption.
|
||||
# *DO NOT* cancel (i.e. return False) without very good reason
|
||||
# (out of band transmission for instance).
|
||||
# e2e should have a priority of 0 here, and out of band transmission
|
||||
# a lower priority
|
||||
# FIXME: trigger not used yet, can be uncommented when e2e full stanza
|
||||
# encryption is implemented
|
||||
# if not self.host_app.trigger.point("send", self, obj):
|
||||
# return
|
||||
super(SatXMPPClient, self).send(obj)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def sendMessageData(self, mess_data):
|
||||
"""Convenient method to send message data to stream
|
||||
|
||||
This method will send mess_data[u'xml'] to stream, but a trigger is there
|
||||
The trigger can't be cancelled, it's a good place for e2e encryption which
|
||||
don't handle full stanza encryption
|
||||
This trigger can return a Deferred (it's an asyncPoint)
|
||||
@param mess_data(dict): message data as constructed by onMessage workflow
|
||||
@return (dict): mess_data (so it can be used in a deferred chain)
|
||||
"""
|
||||
# XXX: This is the last trigger before u"send" (last but one globally)
|
||||
# for sending message.
|
||||
# This is intented for e2e encryption which doesn't do full stanza
|
||||
# encryption (e.g. OTR)
|
||||
# This trigger point can't cancel the method
|
||||
yield self.host_app.trigger.asyncPoint("sendMessageData", self, mess_data,
|
||||
triggers_no_cancel=True)
|
||||
self.send(mess_data["xml"])
|
||||
defer.returnValue(mess_data)
|
||||
|
||||
def feedback(self, to_jid, message, extra=None):
|
||||
"""Send message to frontends
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue