From 13052817bf47e8998c140ca33e955198887e77c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Thu, 24 Mar 2022 19:53:53 +0100 Subject: [PATCH] Remove get_device_list in favor of get_devices and get_active_devices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- ChangeLog | 3 +++ slixmpp_omemo/__init__.py | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index e2b786d..39ff531 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ Version XXX: 2022-XX-XX Maxime “pep” Buquet + * Breaking: + - Removed get_device_list method in favor of newly added get_devices and + get_active_devices methods. * Improvements: - Added py.typed to the repository for static type checking tools - New delete_session method diff --git a/slixmpp_omemo/__init__.py b/slixmpp_omemo/__init__.py index 113b001..ac8af37 100644 --- a/slixmpp_omemo/__init__.py +++ b/slixmpp_omemo/__init__.py @@ -478,7 +478,7 @@ class XEP_0384(BasePlugin): return # XXX: Handle this! if device_ids is None: - device_ids = await self.get_device_list(own_jid) + device_ids = await self.get_active_devices(own_jid) devices = [] for i in device_ids: @@ -527,10 +527,19 @@ class XEP_0384(BasePlugin): own_jid.bare, OMEMO_DEVICES_NS, payload=payload, ) - async def get_device_list(self, jid: JID) -> List[str]: - """Return active device ids. Always contains our own device id.""" + async def get_devices(self, jid: JID) -> Iterable[str]: + """ + Get all devices for a JID. + """ devices = await self._omemo().getDevices(jid.bare) - return devices.get('active', []) + return set(devices.get('active', []) + devices.get('inactive', [])) + + async def get_active_devices(self, jid: JID) -> Iterable[str]: + """ + Return active device ids. Always contains our own device id. + """ + devices = await self._omemo().getDevices(jid.bare) + return set(devices.get('active', [])) async def _should_heartbeat(self, jid: JID, device_id: int, prekey: bool) -> bool: """