From 915e0c9c1ba34ea5a7cd46e0cc5bb41cb04c3846 Mon Sep 17 00:00:00 2001 From: lumi Date: Wed, 23 May 2018 22:17:42 +0100 Subject: [PATCH] Fix list device handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- plugin.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/plugin.py b/plugin.py index e858055..9fd0681 100644 --- a/plugin.py +++ b/plugin.py @@ -14,6 +14,7 @@ from slixmpp.plugins.xep_0384.stanza import OMEMO_BASE_NS from slixmpp.plugins.xep_0384.stanza import OMEMO_DEVICES_NS, OMEMO_BUNDLES_NS from slixmpp.plugins.xep_0384.stanza import Devices, Device, Key, PreKeyPublic from slixmpp.plugins.base import BasePlugin, register_plugin +from slixmpp.exceptions import IqError log = logging.getLogger(__name__) @@ -153,15 +154,24 @@ class XEP_0384(BasePlugin): asyncio.ensure_future(self._set_device_list()) async def _set_device_list(self): - iq = await self.xmpp['xep_0060'].get_items( - self.xmpp.boundjid.bare, OMEMO_DEVICES_NS, - ) jid = self.xmpp.boundjid.bare - items = iq['pubsub']['items'] - self._store_device_ids(jid, items) + + try: + iq = await self.xmpp['xep_0060'].get_items( + self.xmpp.boundjid.bare, OMEMO_DEVICES_NS, + ) + log.debug("DEVICES %r", iq) + items = iq['pubsub']['items'] + self._store_device_ids(jid, items) + except IqError as iq_err: + if iq_err.condition == "item-not-found": + log.debug("NO DEVICES") + self._store_device_ids(jid, []) + else: + return # XXX: Handle this! # Verify that this device in the list and set it if necessary - if self._device_id in self.device_ids[jid]: + if self._device_id in self.device_ids.get(jid, []): return self.device_ids[jid].append(self._device_id)