diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ce849e..9b205ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +### Changed +- Attempt device list download with max_items before falling back to full download + ## [1.2.1] - 19th of October, 2024 ### Fixed diff --git a/slixmpp_omemo/xep_0384.py b/slixmpp_omemo/xep_0384.py index 5f82f01..6618c80 100644 --- a/slixmpp_omemo/xep_0384.py +++ b/slixmpp_omemo/xep_0384.py @@ -368,15 +368,27 @@ async def _download_device_list(namespace: str, bare_jid: str) -> Dict[int, Opti raise UnknownNamespace(f"Unknown namespace: {namespace}") try: - items_iq = await xep_0060.get_items(JID(bare_jid), node) - except Exception as e: + items_iq = await xep_0060.get_items(JID(bare_jid), node, max_items=1) + except Exception as e: # pylint: disable=broad-exception-caught if isinstance(e, IqError): if e.condition == "item-not-found": return {} - raise DeviceListDownloadFailed( - f"Device list download failed for {bare_jid} under namespace {namespace}" - ) from e + log.warning( + f"Device list download failed for {bare_jid} under namespace {namespace}, trying again" + f" without max_items" + ) + + try: + items_iq = await xep_0060.get_items(JID(bare_jid), node) + except Exception as ex: + if isinstance(ex, IqError): + if ex.condition == "item-not-found": + return {} + + raise DeviceListDownloadFailed( + f"Device list download failed for {bare_jid} under namespace {namespace}" + ) from ex items = items_iq["pubsub"]["items"]