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]: