comparison sat/plugins/plugin_xep_0384.py @ 3584:edc79cefe968

plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
author Goffi <goffi@goffi.org>
date Wed, 30 Jun 2021 16:19:14 +0200
parents 888109774673
children e4054b648111
comparison
equal deleted inserted replaced
3583:16ade4ad63f3 3584:edc79cefe968
790 device_id=device_elt['id'])) 790 device_id=device_elt['id']))
791 else: 791 else:
792 devices.add(device_id) 792 devices.add(device_id)
793 return devices 793 return devices
794 794
795 @defer.inlineCallbacks 795 async def getDevices(self, client, entity_jid=None):
796 def getDevices(self, client, entity_jid=None):
797 """Retrieve list of registered OMEMO devices 796 """Retrieve list of registered OMEMO devices
798 797
799 @param entity_jid(jid.JID, None): get devices from this entity 798 @param entity_jid(jid.JID, None): get devices from this entity
800 None to get our own devices 799 None to get our own devices
801 @return (set(int)): list of devices 800 @return (set(int)): list of devices
802 """ 801 """
803 if entity_jid is not None: 802 if entity_jid is not None:
804 assert not entity_jid.resource 803 assert not entity_jid.resource
805 try: 804 try:
806 items, metadata = yield self._p.getItems(client, entity_jid, NS_OMEMO_DEVICES) 805 items, metadata = await self._p.getItems(client, entity_jid, NS_OMEMO_DEVICES)
807 except exceptions.NotFound: 806 except exceptions.NotFound:
808 log.info(_("there is no node to handle OMEMO devices")) 807 log.info(_("there is no node to handle OMEMO devices"))
809 defer.returnValue(set()) 808 return set()
810 809
811 devices = self.parseDevices(items) 810 devices = self.parseDevices(items)
812 defer.returnValue(devices) 811 return devices
813 812
814 async def setDevices(self, client, devices): 813 async def setDevices(self, client, devices):
815 log.debug(f"setting devices with {', '.join(str(d) for d in devices)}") 814 log.debug(f"setting devices with {', '.join(str(d) for d in devices)}")
816 list_elt = domish.Element((NS_OMEMO, 'list')) 815 list_elt = domish.Element((NS_OMEMO, 'list'))
817 for device in devices: 816 for device in devices:
829 except Exception as e: 828 except Exception as e:
830 log.warning(_("Can't set devices: {reason}").format(reason=e)) 829 log.warning(_("Can't set devices: {reason}").format(reason=e))
831 830
832 # bundles 831 # bundles
833 832
834 @defer.inlineCallbacks 833 async def getBundles(self, client, entity_jid, devices_ids):
835 def getBundles(self, client, entity_jid, devices_ids):
836 """Retrieve public bundles of an entity devices 834 """Retrieve public bundles of an entity devices
837 835
838 @param entity_jid(jid.JID): bare jid of entity 836 @param entity_jid(jid.JID): bare jid of entity
839 @param devices_id(iterable[int]): ids of the devices bundles to retrieve 837 @param devices_id(iterable[int]): ids of the devices bundles to retrieve
840 @return (tuple(dict[int, ExtendedPublicBundle], list(int))): 838 @return (tuple(dict[int, ExtendedPublicBundle], list(int))):
847 bundles = {} 845 bundles = {}
848 missing = set() 846 missing = set()
849 for device_id in devices_ids: 847 for device_id in devices_ids:
850 node = NS_OMEMO_BUNDLE.format(device_id=device_id) 848 node = NS_OMEMO_BUNDLE.format(device_id=device_id)
851 try: 849 try:
852 items, metadata = yield self._p.getItems(client, entity_jid, node) 850 items, metadata = await self._p.getItems(client, entity_jid, node)
853 except exceptions.NotFound: 851 except exceptions.NotFound:
854 log.warning(_("Bundle missing for device {device_id}") 852 log.warning(_("Bundle missing for device {device_id}")
855 .format(device_id=device_id)) 853 .format(device_id=device_id))
856 missing.add(device_id) 854 missing.add(device_id)
857 continue 855 continue
908 continue 906 continue
909 907
910 bundles[device_id] = ExtendedPublicBundle.parse(omemo_backend, ik, spk, 908 bundles[device_id] = ExtendedPublicBundle.parse(omemo_backend, ik, spk,
911 spkSignature, otpks) 909 spkSignature, otpks)
912 910
913 defer.returnValue((bundles, missing)) 911 return (bundles, missing)
914 912
915 async def setBundle(self, client, bundle, device_id): 913 async def setBundle(self, client, bundle, device_id):
916 """Set public bundle for this device. 914 """Set public bundle for this device.
917 915
918 @param bundle(ExtendedPublicBundle): bundle to publish 916 @param bundle(ExtendedPublicBundle): bundle to publish