diff sat/core/xmpp.py @ 3784:efc34a89e70b

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
author Goffi <goffi@goffi.org>
date Tue, 24 May 2022 17:57:36 +0200
parents 001ea5f4a2f9
children 967a8e109cda
line wrap: on
line diff
--- a/sat/core/xmpp.py	Tue May 24 17:49:14 2022 +0200
+++ b/sat/core/xmpp.py	Tue May 24 17:57:36 2022 +0200
@@ -612,6 +612,43 @@
         """
         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 @@
             # 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 @@
                 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 @@
         )
         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