Make fetch_devices and fetch_bundle public

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2022-03-24 19:58:19 +01:00
parent 3a85411df8
commit c8341e0f83
2 changed files with 18 additions and 12 deletions

View file

@ -6,6 +6,7 @@ Version XXX:
* Improvements:
- Added py.typed to the repository for static type checking tools
- New delete_session method
- New fetch_devices and fetch_bundle methods
Version 0.6.1:
2022-03-14 Maxime “pep” Buquet <pep@bouah.net>
* Improvements:

View file

@ -415,7 +415,10 @@ class XEP_0384(BasePlugin):
else:
log.debug('Not publishing.')
async def _fetch_bundle(self, jid: str, device_id: int) -> Optional[ExtendedPublicBundle]:
async def fetch_bundle(self, jid: JID, device_id: int) -> None:
"""
Fetch bundles for specified jid / device_id pair.
"""
log.debug('Fetching bundle for JID: %r, device: %r', jid, device_id)
node = f'{OMEMO_BUNDLES_NS}:{device_id}'
try:
@ -424,10 +427,18 @@ class XEP_0384(BasePlugin):
return None
bundle = iq['pubsub']['items']['item']['bundle']
return _parse_bundle(self.omemo_backend, bundle)
bundle = _parse_bundle(self.omemo_backend, bundle)
if bundle is not None:
log.debug('Encryption: Bundle %r found!', device_id)
devices = self.bundles.setdefault(jid.bare, {})
devices[device_id] = bundle
else:
log.debug('Encryption: Bundle %r not found!', device_id)
async def _fetch_device_list(self, jid: JID) -> None:
"""Manually query PEP OMEMO_DEVICES_NS nodes"""
async def fetch_devices(self, jid: JID) -> None:
"""
Manually query PEP OMEMO_DEVICES_NS nodes
"""
log.debug('Fetching device list for JID: %r', jid)
iq = await self.xmpp['xep_0060'].get_items(jid.full, OMEMO_DEVICES_NS)
return await self._read_device_list(jid, iq['pubsub']['items'])
@ -819,16 +830,10 @@ class XEP_0384(BasePlugin):
for exn in errors:
if isinstance(exn, omemo.exceptions.NoDevicesException):
log.debug('Encryption: Missing device list for JID: %r', exn.bare_jid)
await self._fetch_device_list(JID(exn.bare_jid))
await self.fetch_devices(JID(exn.bare_jid))
elif isinstance(exn, omemo.exceptions.MissingBundleException):
log.debug('Encryption: Missing bundle for JID: %r, device: %r', exn.bare_jid, exn.device)
bundle = await self._fetch_bundle(exn.bare_jid, exn.device)
if bundle is not None:
log.debug('Encryption: Bundle %r found!', exn.device)
devices = self.bundles.setdefault(exn.bare_jid, {})
devices[exn.device] = bundle
else:
log.debug('Encryption: Bundle %r not found.', exn.device)
await self.fetch_bundle(JID(exn.bare_jid), exn.device)
elif isinstance(exn, omemo.exceptions.TrustException):
# On TrustException, there are two possibilities.
# Either trust has not been explicitely set yet, and is