Merge branch 'initial-publish' into 'master'
Fix #10: ensure device list and bundle are published after startup Closes #10 See merge request poezio/slixmpp-omemo!11
This commit is contained in:
commit
311292a0be
1 changed files with 11 additions and 0 deletions
|
@ -208,6 +208,9 @@ class XEP_0384(BasePlugin):
|
||||||
# OMEMO Bundles used for encryption
|
# OMEMO Bundles used for encryption
|
||||||
bundles = {} # type: Dict[str, Dict[int, ExtendedPublicBundle]]
|
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:
|
def plugin_init(self) -> None:
|
||||||
if not self.backend_loaded:
|
if not self.backend_loaded:
|
||||||
log_str = ("xep_0384 cannot be loaded as the backend omemo library "
|
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.add_event_handler('session_start', self.session_start)
|
||||||
self.xmpp['xep_0060'].map_node_event(OMEMO_DEVICES_NS, 'omemo_device_list')
|
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)
|
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
|
return None
|
||||||
|
|
||||||
def plugin_end(self):
|
def plugin_end(self):
|
||||||
|
@ -258,12 +265,16 @@ class XEP_0384(BasePlugin):
|
||||||
self.xmpp['xep_0163'].remove_interest(OMEMO_DEVICES_NS)
|
self.xmpp['xep_0163'].remove_interest(OMEMO_DEVICES_NS)
|
||||||
|
|
||||||
async def session_start(self, _jid):
|
async def session_start(self, _jid):
|
||||||
|
await self._initial_publish()
|
||||||
|
|
||||||
|
async def _initial_publish(self):
|
||||||
if self.backend_loaded:
|
if self.backend_loaded:
|
||||||
self.xmpp['xep_0163'].add_interest(OMEMO_DEVICES_NS)
|
self.xmpp['xep_0163'].add_interest(OMEMO_DEVICES_NS)
|
||||||
await asyncio.wait([
|
await asyncio.wait([
|
||||||
self._set_device_list(),
|
self._set_device_list(),
|
||||||
self._publish_bundle(),
|
self._publish_bundle(),
|
||||||
])
|
])
|
||||||
|
self._initial_publish_done = True
|
||||||
|
|
||||||
def my_device_id(self) -> int:
|
def my_device_id(self) -> int:
|
||||||
return self._device_id
|
return self._device_id
|
||||||
|
|
Loading…
Reference in a new issue