Skip to content

Commit

Permalink
Attempt device list download with max_items before falling back to fu…
Browse files Browse the repository at this point in the history
…ll download
  • Loading branch information
Syndace committed Oct 22, 2024
1 parent de04230 commit 34b8e4e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 17 additions & 5 deletions slixmpp_omemo/xep_0384.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down

0 comments on commit 34b8e4e

Please sign in to comment.