# HG changeset patch # User Goffi # Date 1664029899 -7200 # Node ID 944f51f9c2b41354846847ee24ac3f4407492fbe # Parent ce5d03772689744994da5cf2f03724a5bf4bae60 core (xmpp): make `send` a blocking method, fix `sendMessageData` calls: original `send` method is blocking, and it is used as such by Wokkel and thus can't be changed to an async method easily. However, an Async method is necessary to have an async trigger at the very end of the send workflow for end-to-end encryption. To workaround that, `send` is an async method which call `a_send`, an async method which actually does the sending. This way legacy method can still call `send` while `a_send` can be await otherwise. Fix calls to `sendMessageData`: the method now being an `async` one, `ensureDeferred` had to be used in some calls. diff -r ce5d03772689 -r 944f51f9c2b4 sat/core/xmpp.py --- a/sat/core/xmpp.py Sat Sep 24 16:08:26 2022 +0200 +++ b/sat/core/xmpp.py Sat Sep 24 16:31:39 2022 +0200 @@ -616,7 +616,7 @@ """ raise NotImplementedError - async def send(self, obj): + async def a_send(self, obj): # original send method accept string # but we restrict to domish.Element to make trigger treatments easier assert isinstance(obj, domish.Element) @@ -630,6 +630,9 @@ return super().send(obj) + def send(self, obj): + defer.ensureDeferred(self.a_send(obj)) + async def sendMessageData(self, mess_data): """Convenient method to send message data to stream @@ -647,7 +650,7 @@ # This trigger point can't cancel the method await self.host_app.trigger.asyncPoint("sendMessageData", self, mess_data, triggers_no_cancel=True) - await self.send(mess_data["xml"]) + await self.a_send(mess_data["xml"]) return mess_data def sendMessage( @@ -738,7 +741,9 @@ pre_xml_treatments.addCallback(lambda __: self.generateMessageXML(data, post_xml_treatments)) pre_xml_treatments.addCallback(lambda __: post_xml_treatments) pre_xml_treatments.addErrback(self._cancelErrorTrap) - post_xml_treatments.addCallback(lambda __: self.sendMessageData(data)) + post_xml_treatments.addCallback( + lambda __: defer.ensureDeferred(self.sendMessageData(data)) + ) if send_only: log.debug(_("Triggers, storage and echo have been inhibited by the " "'send_only' parameter")) diff -r ce5d03772689 -r 944f51f9c2b4 sat/plugins/plugin_xep_0033.py --- a/sat/plugins/plugin_xep_0033.py Sat Sep 24 16:08:26 2022 +0200 +++ b/sat/plugins/plugin_xep_0033.py Sat Sep 24 16:31:39 2022 +0200 @@ -155,7 +155,9 @@ def send(mess_data, skip_send=False): d = defer.Deferred() if not skip_send: - d.addCallback(client.sendMessageData) + d.addCallback( + lambda ret: defer.ensureDeferred(client.sendMessageData(ret)) + ) d.addCallback( lambda ret: defer.ensureDeferred(client.messageAddToHistory(ret)) ) diff -r ce5d03772689 -r 944f51f9c2b4 sat/plugins/plugin_xep_0297.py --- a/sat/plugins/plugin_xep_0297.py Sat Sep 24 16:08:26 2022 +0200 +++ b/sat/plugins/plugin_xep_0297.py Sat Sep 24 16:31:39 2022 +0200 @@ -22,6 +22,8 @@ from sat.core.i18n import _, D_ from sat.core.log import getLogger +from twisted.internet import defer + log = getLogger(__name__) from wokkel import disco, iwokkel @@ -104,7 +106,7 @@ msg.addChild(forwarded_elt) client = self.host.getClient(profile_key) - return client.sendMessageData({"xml": msg}) + return defer.ensureDeferred(client.sendMessageData({"xml": msg})) @implementer(iwokkel.IDisco)