diff sat/plugins/plugin_xep_0048.py @ 4001:32d714a8ea51

plugin XEP-0045: dot not wait for MAM retrieval to be completed: in `_join_MAM`, `room.fully_joined` is called before retrieving the MAM archive, as the process can be very long, and is not necessary to have the room working (message can be received after being in the room, and added out of order). This avoid blocking the `join` workflow for an extended time. Some renaming and coroutine integrations.
author Goffi <goffi@goffi.org>
date Fri, 10 Mar 2023 17:22:41 +0100
parents be6d91572633
children 524856bd7b19
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0048.py	Fri Mar 10 17:01:09 2023 +0100
+++ b/sat/plugins/plugin_xep_0048.py	Fri Mar 10 17:22:41 2023 +0100
@@ -101,16 +101,15 @@
         except KeyError:
             log.info(_("Text commands not available"))
 
-    @defer.inlineCallbacks
-    def profileConnected(self, client):
+    async def profileConnected(self, client):
         local = client.bookmarks_local = PersistentBinaryDict(
             NS_BOOKMARKS, client.profile
         )
-        yield local.load()
+        await local.load()
         if not local:
             local[XEP_0048.MUC_TYPE] = dict()
             local[XEP_0048.URL_TYPE] = dict()
-        private = yield self._getServerBookmarks("private", client.profile)
+        private = await self._getServerBookmarks("private", client.profile)
         pubsub = client.bookmarks_pubsub = None
 
         for bookmarks in (local, private, pubsub):
@@ -118,7 +117,9 @@
                 for (room_jid, data) in list(bookmarks[XEP_0048.MUC_TYPE].items()):
                     if data.get("autojoin", "false") == "true":
                         nick = data.get("nick", client.jid.user)
-                        self.host.plugins["XEP-0045"].join(client, room_jid, nick, {})
+                        defer.ensureDeferred(
+                            self.host.plugins["XEP-0045"].join(client, room_jid, nick, {})
+                        )
 
         # we don't use a DeferredList to gather result here, as waiting for all room would
         # slow down a lot the connection process, and result in a bad user experience.