From 26fbb7e28ccffef4e93c77f7a72eff5e12940fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Mon, 15 May 2023 16:05:27 +0200 Subject: [PATCH] WIP: Fix non-awaited task 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 | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/slixmpp_omemo/__init__.py b/slixmpp_omemo/__init__.py index 1eb7b53..6aa6737 100644 --- a/slixmpp_omemo/__init__.py +++ b/slixmpp_omemo/__init__.py @@ -236,7 +236,6 @@ class XEP_0384(BasePlugin): "no data directory specified.") self._device_id = _load_device_id(self.data_dir) - asyncio.create_task(self.session_start_omemo()) self.xmpp.add_event_handler('session_start', self.session_start) self.xmpp['xep_0060'].map_node_event(OMEMO_DEVICES_NS, 'omemo_device_list') @@ -245,7 +244,7 @@ class XEP_0384(BasePlugin): # If this plugin is loaded after 'session_start' has fired, we still # need to publish bundles if self.xmpp.is_connected and not self._initial_publish_done: - asyncio.create_task(self._initial_publish()) + asyncio.ensure_future(self.session_start(None)) def plugin_end(self): if not self.backend_loaded: @@ -255,7 +254,7 @@ class XEP_0384(BasePlugin): self.xmpp.remove_event_handler('omemo_device_list_publish', self._receive_device_list) self.xmpp['xep_0163'].remove_interest(OMEMO_DEVICES_NS) - async def session_start_omemo(self): + async def session_start(self, _jid): """Creates the OMEMO session object""" storage = self.storage_backend @@ -277,15 +276,14 @@ class XEP_0384(BasePlugin): log.error("Couldn't load the OMEMO object; ¯\\_(ツ)_/¯") raise PluginCouldNotLoad from exn + await self._initial_publish() + def _omemo(self) -> SessionManager: """Helper method to unguard potentially uninitialized SessionManager""" if self.__omemo_session is None: raise UninitializedOMEMOSession return self.__omemo_session - async def session_start(self, _jid): - await self._initial_publish() - async def _initial_publish(self): if self.backend_loaded: self.xmpp['xep_0163'].add_interest(OMEMO_DEVICES_NS)