Expose fetch_devices and fetch_bundles

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2022-07-10 22:31:25 +02:00
parent dccb877b41
commit 8e9add345a
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2
2 changed files with 27 additions and 5 deletions

View file

@ -1,3 +1,9 @@
Version 0.7.1:
xxxx-xx-xx Maxime “pep” Buquet <pep@bouah.net>
* Changes:
- fetch_bundle and fetch_device methods are now public
* Added:
- New fetch_bundles method to fetch all bundles at once
Version 0.7.0: Version 0.7.0:
2022-04-03 Maxime “pep” Buquet <pep@bouah.net> 2022-04-03 Maxime “pep” Buquet <pep@bouah.net>
* Breaking: * Breaking:

View file

@ -415,9 +415,9 @@ class XEP_0384(BasePlugin):
else: else:
log.debug('Not publishing.') log.debug('Not publishing.')
async def _fetch_bundle(self, jid: JID, device_id: int) -> None: async def fetch_bundle(self, jid: JID, device_id: int) -> None:
""" """
Fetch bundles for specified jid / device_id pair. Fetch bundle for specified jid / device_id pair.
""" """
log.debug('Fetching bundle for JID: %r, device: %r', jid, device_id) log.debug('Fetching bundle for JID: %r, device: %r', jid, device_id)
node = f'{OMEMO_BUNDLES_NS}:{device_id}' node = f'{OMEMO_BUNDLES_NS}:{device_id}'
@ -435,7 +435,23 @@ class XEP_0384(BasePlugin):
else: else:
log.debug('Encryption: Bundle %r not found!', device_id) log.debug('Encryption: Bundle %r not found!', device_id)
async def _fetch_devices(self, jid: JID) -> None: async def fetch_bundles(self, jid: JID) -> None:
"""
Fetch bundles of active devices for specified JID.
This is a helper function to allow the user to request a store
update. Failed bundles are not retried.
"""
# Ignore failures
await asyncio.gather(
*map(
lambda did: self.fetch_bundle(jid, did),
self.get_active_devices(jid)
), # type: ignore
return_exceptions=True,
)
async def fetch_devices(self, jid: JID) -> None:
""" """
Manually query PEP OMEMO_DEVICES_NS nodes Manually query PEP OMEMO_DEVICES_NS nodes
""" """
@ -829,10 +845,10 @@ class XEP_0384(BasePlugin):
for exn in errors: for exn in errors:
if isinstance(exn, omemo.exceptions.NoDevicesException): if isinstance(exn, omemo.exceptions.NoDevicesException):
log.debug('Encryption: Missing device list for JID: %r', exn.bare_jid) log.debug('Encryption: Missing device list for JID: %r', exn.bare_jid)
await self._fetch_devices(JID(exn.bare_jid)) await self.fetch_devices(JID(exn.bare_jid))
elif isinstance(exn, omemo.exceptions.MissingBundleException): elif isinstance(exn, omemo.exceptions.MissingBundleException):
log.debug('Encryption: Missing bundle for JID: %r, device: %r', exn.bare_jid, exn.device) log.debug('Encryption: Missing bundle for JID: %r, device: %r', exn.bare_jid, exn.device)
await self._fetch_bundle(JID(exn.bare_jid), exn.device) await self.fetch_bundle(JID(exn.bare_jid), exn.device)
elif isinstance(exn, omemo.exceptions.TrustException): elif isinstance(exn, omemo.exceptions.TrustException):
# On TrustException, there are two possibilities. # On TrustException, there are two possibilities.
# Either trust has not been explicitely set yet, and is # Either trust has not been explicitely set yet, and is