From a07c3d97454268ae56a8146c303ab09fcdc8dce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Thu, 22 Aug 2019 19:43:49 +0200 Subject: [PATCH] Only use publish-options if advertized by the server 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, 14 insertions(+), 7 deletions(-) diff --git a/slixmpp_omemo/__init__.py b/slixmpp_omemo/__init__.py index e3bbd28..2de37d0 100644 --- a/slixmpp_omemo/__init__.py +++ b/slixmpp_omemo/__init__.py @@ -52,6 +52,7 @@ except (ImportError,): HAS_OMEMO = False TRUE_VALUES = {True, 'true', '1'} +PUBLISH_OPTIONS_NODE = 'http://jabber.org/protocol/pubsub#publish-options' def b64enc(data: bytes) -> str: @@ -229,16 +230,22 @@ class XEP_0384(BasePlugin): def my_device_id(self) -> int: return self._device_id - def _generate_bundle_iq(self) -> Iq: + async def _generate_bundle_iq(self) -> Iq: bundle = self._omemo.public_bundle.serialize(self.omemo_backend) - options = _make_publish_options_form({ - 'pubsub#persist_items': True, - 'pubsub#access_model': 'open', - }) + jid = self.xmpp.boundjid + items = await self.xmpp['xep_0030'].get_items(jid) + publish_options = PUBLISH_OPTIONS_NODE in items['features'] iq = self.xmpp.Iq(stype='set') - iq['pubsub']['publish_options'] = options + + if publish_options: + options = _make_publish_options_form({ + 'pubsub#persist_items': True, + 'pubsub#access_model': 'open', + }) + iq['pubsub']['publish_options'] = options + publish = iq['pubsub']['publish'] publish['node'] = '%s:%d' % (OMEMO_BUNDLES_NS, self._device_id) payload = publish['item']['bundle'] @@ -263,7 +270,7 @@ class XEP_0384(BasePlugin): async def _publish_bundle(self) -> None: if self._omemo.republish_bundle: - iq = self._generate_bundle_iq() + iq = await self._generate_bundle_iq() await iq.send() async def _fetch_bundle(self, jid: str, device_id: int) -> Optional[ExtendedPublicBundle]: