diff sat/core/xmpp.py @ 3911:8289ac1b34f4

plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo: - support for both (modern) OMEMO under the `urn:xmpp:omemo:2` namespace and (legacy) OMEMO under the `eu.siacs.conversations.axolotl` namespace - maintains one identity across both versions of OMEMO - migrates data from the old plugin - includes more features for protocol stability - uses SCE for modern OMEMO - fully type-checked, linted and format-checked - added type hints to various pieces of backend code used by the plugin - added stubs for some Twisted APIs used by the plugin under stubs/ (use `export MYPYPATH=stubs/` before running mypy) - core (xmpp): enabled `send` trigger and made it an asyncPoint fix 375
author Syndace <me@syndace.dev>
date Tue, 23 Aug 2022 21:06:24 +0200
parents 967a8e109cda
children 944f51f9c2b4
line wrap: on
line diff
--- a/sat/core/xmpp.py	Thu Sep 22 12:03:12 2022 +0200
+++ b/sat/core/xmpp.py	Tue Aug 23 21:06:24 2022 +0200
@@ -550,10 +550,14 @@
         ).toResponse(iq_elt)
         self.xmlstream.send(iq_error_elt)
 
-    def generateMessageXML(self, data, post_xml_treatments=None):
+    def generateMessageXML(
+        self,
+        data: core_types.MessageData,
+        post_xml_treatments: Optional[defer.Deferred] = None
+    ) -> core_types.MessageData:
         """Generate <message/> stanza from message data
 
-        @param data(dict): message data
+        @param data: message data
             domish element will be put in data['xml']
             following keys are needed:
                 - from
@@ -563,9 +567,9 @@
                 - type
                 - subject
                 - extra
-        @param post_xml_treatments(Deferred): a Deferred which will be called with data
-            once XML is generated
-        @return (dict) message data
+        @param post_xml_treatments: a Deferred which will be called with data once XML is
+            generated
+        @return: message data
         """
         data["xml"] = message_elt = domish.Element((None, "message"))
         message_elt["to"] = data["to"].full()
@@ -612,7 +616,7 @@
         """
         raise NotImplementedError
 
-    def send(self, obj):
+    async 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)
@@ -622,14 +626,11 @@
         #      (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
+        if not (await self.host_app.trigger.asyncPoint("send", self, obj)):
+            return
         super().send(obj)
 
-    @defer.inlineCallbacks
-    def sendMessageData(self, mess_data):
+    async 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
@@ -644,10 +645,10 @@
         #      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,
+        await self.host_app.trigger.asyncPoint("sendMessageData", self, mess_data,
             triggers_no_cancel=True)
-        self.send(mess_data["xml"])
-        defer.returnValue(mess_data)
+        await self.send(mess_data["xml"])
+        return mess_data
 
     def sendMessage(
             self, to_jid, message, subject=None, mess_type="auto", extra=None, uid=None,
@@ -824,6 +825,9 @@
         return ClientPluginWrapper(self, plugin_name, missing)
 
 
+ExtraDict = dict  # TODO
+
+
 @implementer(iwokkel.IDisco)
 class SatXMPPClient(SatXMPPEntity, wokkel_client.XMPPClient):
     trigger_suffix = ""
@@ -930,15 +934,20 @@
         )
         post_xml_treatments.addCallback(self.messageSendToBridge)
 
-    def feedback(self, to_jid, message, extra=None):
+    def feedback(
+        self,
+        to_jid: jid.JID,
+        message: str,
+        extra: Optional[ExtraDict] = None
+    ) -> None:
         """Send message to frontends
 
         This message will be an info message, not recorded in history.
         It can be used to give feedback of a command
-        @param to_jid(jid.JID): destinee jid
-        @param message(unicode): message to send to frontends
-        @param extra(None, dict): extra data to use
-            in particular, info subtype can be specified with MESS_EXTRA_INFO
+        @param to_jid: destinee jid
+        @param message: message to send to frontends
+        @param extra: extra data to use in particular, info subtype can be specified with
+            MESS_EXTRA_INFO
         """
         if extra is None:
             extra = {}