From b380bfa7d6d69be866d81f2840f89fc0e427791c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Tue, 11 Feb 2020 00:29:31 +0100 Subject: [PATCH] Ensure devicelist and bundles are published after receiving precondition-not-met 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 | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/slixmpp_omemo/__init__.py b/slixmpp_omemo/__init__.py index 9842ce4..1f6d978 100644 --- a/slixmpp_omemo/__init__.py +++ b/slixmpp_omemo/__init__.py @@ -299,7 +299,7 @@ class XEP_0384(BasePlugin): form, ) - async def _generate_bundle_iq(self) -> Iq: + async def _generate_bundle_iq(self, publish_options: bool = True) -> Iq: bundle = self._omemo.public_bundle.serialize(self.omemo_backend) jid = self.xmpp.boundjid @@ -328,7 +328,7 @@ class XEP_0384(BasePlugin): prekeys.append(prekey) payload['prekeys'] = prekeys - if publish_options: + if publish_options and publish_options: options = _make_publish_options_form({ 'pubsub#persist_items': True, 'pubsub#access_model': 'open', @@ -354,7 +354,13 @@ class XEP_0384(BasePlugin): 'Trying to configure manually..') # TODO: We should attempt setting this node to the same # access_model as the devicelist node for completness. - await self._set_node_config(OMEMO_BUNDLES_NS) + try: + await self._set_node_config(OMEMO_BUNDLES_NS) + except IqError: + log.debug('Failed to set node to persistent after precondition-not-met') + raise + iq = await self._generate_bundle_iq(publish_options=False) + await iq.send() async def _fetch_bundle(self, jid: str, device_id: int) -> Optional[ExtendedPublicBundle]: node = '%s:%d' % (OMEMO_BUNDLES_NS, device_id) @@ -456,7 +462,14 @@ class XEP_0384(BasePlugin): log.debug('The node we tried to publish was already ' 'existing with a different configuration. ' 'Trying to configure manually..') - await self._set_node_config(OMEMO_DEVICES_NS) + try: + await self._set_node_config(OMEMO_DEVICES_NS) + except IqError: + log.debug('Failed to set node to persistent after precondition-not-met') + raise + await self.xmpp['xep_0060'].publish( + own_jid.bare, OMEMO_DEVICES_NS, payload=payload, + ) def get_device_list(self, jid: JID) -> List[str]: """Return active device ids. Always contains our own device id."""