changeset 3434:c84c54c6b046

plugin XEP-0234: make `fileJingleRequest` async to fix call of `initiate`
author Goffi <goffi@goffi.org>
date Fri, 04 Dec 2020 12:32:05 +0100
parents 63d20854df3a
children df775db4c49b
files sat/plugins/plugin_xep_0234.py
diffstat 1 files changed, 5 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0234.py	Fri Dec 04 12:30:46 2020 +0100
+++ b/sat/plugins/plugin_xep_0234.py	Fri Dec 04 12:32:05 2020 +0100
@@ -351,7 +351,7 @@
             self, peer_jid, filepath, name="", file_hash="", hash_algo="", extra=None,
             profile=C.PROF_KEY_NONE):
         client = self.host.getClient(profile)
-        return self.fileJingleRequest(
+        return defer.ensureDeferred(self.fileJingleRequest(
             client,
             jid.JID(peer_jid),
             filepath,
@@ -359,10 +359,9 @@
             file_hash or None,
             hash_algo or None,
             extra or None,
-        )
+        ))
 
-    @defer.inlineCallbacks
-    def fileJingleRequest(
+    async def fileJingleRequest(
             self, client, peer_jid, filepath, name=None, file_hash=None, hash_algo=None,
             extra=None):
         """Request a file using jingle file transfer
@@ -384,7 +383,7 @@
         else:
             if hash_algo is not None:
                 raise ValueError(_("file_hash must be set if hash_algo is set"))
-        yield self._j.initiate(
+        await self._j.initiate(
             client,
             peer_jid,
             [
@@ -400,8 +399,7 @@
                 }
             ],
         )
-        progress_id = yield progress_id_d
-        defer.returnValue(progress_id)
+        return await progress_id_d
 
     # jingle callbacks