comparison sat/core/sat_main.py @ 3140:46a6251713d3

core: fixed `findByFeatures`: jids where not correctly put in `found_own` and `found_roster` lists.
author Goffi <goffi@goffi.org>
date Wed, 29 Jan 2020 12:38:48 +0100
parents 9d0df638c8b4
children d10b2368684e
comparison
equal deleted inserted replaced
3139:ca61807f724c 3140:46a6251713d3
904 return self.memory.disco.findFeaturesSet(*args, **kwargs) 904 return self.memory.disco.findFeaturesSet(*args, **kwargs)
905 905
906 def _findByFeatures(self, namespaces, identities, bare_jids, service, roster, own_jid, 906 def _findByFeatures(self, namespaces, identities, bare_jids, service, roster, own_jid,
907 local_device, profile_key): 907 local_device, profile_key):
908 client = self.getClient(profile_key) 908 client = self.getClient(profile_key)
909 return self.findByFeatures(client, namespaces, identities, bare_jids, service, 909 return defer.ensureDeferred(self.findByFeatures(
910 roster, own_jid, local_device,) 910 client, namespaces, identities, bare_jids, service, roster, own_jid,
911 911 local_device))
912 @defer.inlineCallbacks 912
913 def findByFeatures(self, client, namespaces, identities=None, bare_jids=False, 913 async def findByFeatures(
914 service=True, roster=True, own_jid=True, local_device=False): 914 self, client, namespaces, identities=None, bare_jids=False, service=True,
915 """retrieve all services or contacts managing a set a features 915 roster=True, own_jid=True, local_device=False):
916 """Retrieve all services or contacts managing a set a features
916 917
917 @param namespaces(list[unicode]): features which must be handled 918 @param namespaces(list[unicode]): features which must be handled
918 @param identities(list[tuple[unicode,unicode]], None): if not None or empty, 919 @param identities(list[tuple[unicode,unicode]], None): if not None or empty,
919 only keep those identities tuple must by (category, type) 920 only keep those identities tuple must by (category, type)
920 @param bare_jids(bool): retrieve only bare_jids if True 921 @param bare_jids(bool): retrieve only bare_jids if True
940 ) 941 )
941 found_service = {} 942 found_service = {}
942 found_own = {} 943 found_own = {}
943 found_roster = {} 944 found_roster = {}
944 if service: 945 if service:
945 services_jids = yield self.findFeaturesSet(client, namespaces) 946 services_jids = await self.findFeaturesSet(client, namespaces)
946 services_jids = list(services_jids) # we need a list to map results below 947 services_jids = list(services_jids) # we need a list to map results below
947 services_infos = yield defer.DeferredList( 948 services_infos = await defer.DeferredList(
948 [self.getDiscoInfos(client, service_jid) for service_jid in services_jids] 949 [self.getDiscoInfos(client, service_jid) for service_jid in services_jids]
949 ) 950 )
950 951
951 for idx, (success, infos) in enumerate(services_infos): 952 for idx, (success, infos) in enumerate(services_infos):
952 service_jid = services_jids[idx] 953 service_jid = services_jids[idx]
968 if own_jid: 969 if own_jid:
969 to_find.append((found_own, [client.jid.userhostJID()])) 970 to_find.append((found_own, [client.jid.userhostJID()]))
970 if roster: 971 if roster:
971 to_find.append((found_roster, client.roster.getJids())) 972 to_find.append((found_roster, client.roster.getJids()))
972 973
973 full_jids = []
974 d_list = []
975
976 for found, jids in to_find: 974 for found, jids in to_find:
975 full_jids = []
976 disco_defers = []
977
977 for jid_ in jids: 978 for jid_ in jids:
978 if jid_.resource: 979 if jid_.resource:
979 if bare_jids: 980 if bare_jids:
980 continue 981 continue
981 resources = [jid_.resource] 982 resources = [jid_.resource]
996 full_jid = jid.JID(tuple=(jid_.user, jid_.host, resource)) 997 full_jid = jid.JID(tuple=(jid_.user, jid_.host, resource))
997 if full_jid == client.jid and not local_device: 998 if full_jid == client.jid and not local_device:
998 continue 999 continue
999 full_jids.append(full_jid) 1000 full_jids.append(full_jid)
1000 1001
1001 d_list.append(self.getDiscoInfos(client, full_jid)) 1002 disco_defers.append(self.getDiscoInfos(client, full_jid))
1002 1003
1003 d_list = defer.DeferredList(d_list) 1004 d_list = defer.DeferredList(disco_defers)
1004 # XXX: 10 seconds may be too low for slow connections (e.g. mobiles) 1005 # XXX: 10 seconds may be too low for slow connections (e.g. mobiles)
1005 # but for discovery, that's also the time the user will wait the first time 1006 # but for discovery, that's also the time the user will wait the first time
1006 # before seing the page, if something goes wrong. 1007 # before seing the page, if something goes wrong.
1007 d_list.addTimeout(10, reactor) 1008 d_list.addTimeout(10, reactor)
1008 infos_data = yield d_list 1009 infos_data = await d_list
1009 1010
1010 for idx, (success, infos) in enumerate(infos_data): 1011 for idx, (success, infos) in enumerate(infos_data):
1011 full_jid = full_jids[idx] 1012 full_jid = full_jids[idx]
1012 if not success: 1013 if not success:
1013 log.warning( 1014 log.warning(
1014 _("Can't retrieve {full_jid} infos, ignoring") 1015 _("Can't retrieve {full_jid} infos, ignoring")
1015 .format(full_jid=full_jid.full())) 1016 .format(full_jid=full_jid.full()))
1016 continue
1017 if infos.features.issuperset(namespaces):
1018 if identities is not None and not set(
1019 infos.identities.keys()
1020 ).issuperset(identities):
1021 continue 1017 continue
1022 found_identities = [ 1018 if infos.features.issuperset(namespaces):
1023 (cat, type_, name or "") 1019 if identities is not None and not set(
1024 for (cat, type_), name in infos.identities.items() 1020 infos.identities.keys()
1025 ] 1021 ).issuperset(identities):
1026 found[full_jid.full()] = found_identities 1022 continue
1027 1023 found_identities = [
1028 defer.returnValue((found_service, found_own, found_roster)) 1024 (cat, type_, name or "")
1025 for (cat, type_), name in infos.identities.items()
1026 ]
1027 found[full_jid.full()] = found_identities
1028
1029 return (found_service, found_own, found_roster)
1029 1030
1030 ## Generic HMI ## 1031 ## Generic HMI ##
1031 1032
1032 def _killAction(self, keep_id, client): 1033 def _killAction(self, keep_id, client):
1033 log.debug("Killing action {} for timeout".format(keep_id)) 1034 log.debug("Killing action {} for timeout".format(keep_id))