From fbe5e36c3e6e6327d8b0c0cc81dee6a1420256e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Wed, 14 Jul 2021 10:43:59 +0200 Subject: [PATCH 1/2] Fix #10: ensure device list and bundle are published after startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- slixmpp_omemo/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/slixmpp_omemo/__init__.py b/slixmpp_omemo/__init__.py index b31d238..7a2bc52 100644 --- a/slixmpp_omemo/__init__.py +++ b/slixmpp_omemo/__init__.py @@ -208,6 +208,9 @@ class XEP_0384(BasePlugin): # OMEMO Bundles used for encryption bundles = {} # type: Dict[str, Dict[int, ExtendedPublicBundle]] + # Used at startup to prevent publishing device list and bundles multiple times + _initial_publish_done = False + def plugin_init(self) -> None: if not self.backend_loaded: log_str = ("xep_0384 cannot be loaded as the backend omemo library " @@ -247,6 +250,10 @@ class XEP_0384(BasePlugin): self.xmpp.add_event_handler('session_start', self.session_start) self.xmpp['xep_0060'].map_node_event(OMEMO_DEVICES_NS, 'omemo_device_list') self.xmpp.add_event_handler('omemo_device_list_publish', self._receive_device_list) + + if self.xmpp.is_connected and not self._initial_publish_done: + asyncio.ensure_future(self._initial_publish()) + return None def plugin_end(self): @@ -258,12 +265,16 @@ class XEP_0384(BasePlugin): self.xmpp['xep_0163'].remove_interest(OMEMO_DEVICES_NS) async def session_start(self, _jid): - if self.backend_loaded: + if self.backend_loaded and not self._initial_publish_done: + await self._initial_publish() + + async def _initial_publish(self): self.xmpp['xep_0163'].add_interest(OMEMO_DEVICES_NS) await asyncio.wait([ self._set_device_list(), self._publish_bundle(), ]) + self._initial_publish_done = True def my_device_id(self) -> int: return self._device_id From aa54f58649fd544c78e09b32aa39ecd44c02e31a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Wed, 14 Jul 2021 12:32:36 +0200 Subject: [PATCH 2/2] Always publish on session_start MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The condition wasn't necessary in session_start for PEP nodes not to be published multiple times. This also fixes the fact that we weren't publishing on reconnect. And also fixes one indentation level too many in the _initial_publish method. Signed-off-by: Maxime “pep” Buquet --- slixmpp_omemo/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slixmpp_omemo/__init__.py b/slixmpp_omemo/__init__.py index 7a2bc52..993be34 100644 --- a/slixmpp_omemo/__init__.py +++ b/slixmpp_omemo/__init__.py @@ -265,10 +265,10 @@ class XEP_0384(BasePlugin): self.xmpp['xep_0163'].remove_interest(OMEMO_DEVICES_NS) async def session_start(self, _jid): - if self.backend_loaded and not self._initial_publish_done: - await self._initial_publish() + await self._initial_publish() async def _initial_publish(self): + if self.backend_loaded: self.xmpp['xep_0163'].add_interest(OMEMO_DEVICES_NS) await asyncio.wait([ self._set_device_list(),