comparison 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
comparison
equal deleted inserted replaced
4000:2d59974a8e3e 4001:32d714a8ea51
99 try: 99 try:
100 self.host.plugins[C.TEXT_CMDS].registerTextCommands(self) 100 self.host.plugins[C.TEXT_CMDS].registerTextCommands(self)
101 except KeyError: 101 except KeyError:
102 log.info(_("Text commands not available")) 102 log.info(_("Text commands not available"))
103 103
104 @defer.inlineCallbacks 104 async def profileConnected(self, client):
105 def profileConnected(self, client):
106 local = client.bookmarks_local = PersistentBinaryDict( 105 local = client.bookmarks_local = PersistentBinaryDict(
107 NS_BOOKMARKS, client.profile 106 NS_BOOKMARKS, client.profile
108 ) 107 )
109 yield local.load() 108 await local.load()
110 if not local: 109 if not local:
111 local[XEP_0048.MUC_TYPE] = dict() 110 local[XEP_0048.MUC_TYPE] = dict()
112 local[XEP_0048.URL_TYPE] = dict() 111 local[XEP_0048.URL_TYPE] = dict()
113 private = yield self._getServerBookmarks("private", client.profile) 112 private = await self._getServerBookmarks("private", client.profile)
114 pubsub = client.bookmarks_pubsub = None 113 pubsub = client.bookmarks_pubsub = None
115 114
116 for bookmarks in (local, private, pubsub): 115 for bookmarks in (local, private, pubsub):
117 if bookmarks is not None: 116 if bookmarks is not None:
118 for (room_jid, data) in list(bookmarks[XEP_0048.MUC_TYPE].items()): 117 for (room_jid, data) in list(bookmarks[XEP_0048.MUC_TYPE].items()):
119 if data.get("autojoin", "false") == "true": 118 if data.get("autojoin", "false") == "true":
120 nick = data.get("nick", client.jid.user) 119 nick = data.get("nick", client.jid.user)
121 self.host.plugins["XEP-0045"].join(client, room_jid, nick, {}) 120 defer.ensureDeferred(
121 self.host.plugins["XEP-0045"].join(client, room_jid, nick, {})
122 )
122 123
123 # we don't use a DeferredList to gather result here, as waiting for all room would 124 # we don't use a DeferredList to gather result here, as waiting for all room would
124 # slow down a lot the connection process, and result in a bad user experience. 125 # slow down a lot the connection process, and result in a bad user experience.
125 126
126 @defer.inlineCallbacks 127 @defer.inlineCallbacks