Mercurial > libervia-backend
changeset 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 (2020-01-29) |
parents | ca61807f724c |
children | 49962f9a238a |
files | sat/core/sat_main.py sat/plugins/plugin_adhoc_dbus.py |
diffstat | 2 files changed, 38 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/sat/core/sat_main.py Wed Jan 29 11:19:47 2020 +0100 +++ b/sat/core/sat_main.py Wed Jan 29 12:38:48 2020 +0100 @@ -906,13 +906,14 @@ def _findByFeatures(self, namespaces, identities, bare_jids, service, roster, own_jid, local_device, profile_key): client = self.getClient(profile_key) - return self.findByFeatures(client, namespaces, identities, bare_jids, service, - roster, own_jid, local_device,) + return defer.ensureDeferred(self.findByFeatures( + client, namespaces, identities, bare_jids, service, roster, own_jid, + local_device)) - @defer.inlineCallbacks - def findByFeatures(self, client, namespaces, identities=None, bare_jids=False, - service=True, roster=True, own_jid=True, local_device=False): - """retrieve all services or contacts managing a set a features + async def findByFeatures( + self, client, namespaces, identities=None, bare_jids=False, service=True, + roster=True, own_jid=True, local_device=False): + """Retrieve all services or contacts managing a set a features @param namespaces(list[unicode]): features which must be handled @param identities(list[tuple[unicode,unicode]], None): if not None or empty, @@ -942,9 +943,9 @@ found_own = {} found_roster = {} if service: - services_jids = yield self.findFeaturesSet(client, namespaces) + services_jids = await self.findFeaturesSet(client, namespaces) services_jids = list(services_jids) # we need a list to map results below - services_infos = yield defer.DeferredList( + services_infos = await defer.DeferredList( [self.getDiscoInfos(client, service_jid) for service_jid in services_jids] ) @@ -970,10 +971,10 @@ if roster: to_find.append((found_roster, client.roster.getJids())) - full_jids = [] - d_list = [] + for found, jids in to_find: + full_jids = [] + disco_defers = [] - for found, jids in to_find: for jid_ in jids: if jid_.resource: if bare_jids: @@ -998,34 +999,34 @@ continue full_jids.append(full_jid) - d_list.append(self.getDiscoInfos(client, full_jid)) + disco_defers.append(self.getDiscoInfos(client, full_jid)) - d_list = defer.DeferredList(d_list) - # XXX: 10 seconds may be too low for slow connections (e.g. mobiles) - # but for discovery, that's also the time the user will wait the first time - # before seing the page, if something goes wrong. - d_list.addTimeout(10, reactor) - infos_data = yield d_list + d_list = defer.DeferredList(disco_defers) + # XXX: 10 seconds may be too low for slow connections (e.g. mobiles) + # but for discovery, that's also the time the user will wait the first time + # before seing the page, if something goes wrong. + d_list.addTimeout(10, reactor) + infos_data = await d_list - for idx, (success, infos) in enumerate(infos_data): - full_jid = full_jids[idx] - if not success: - log.warning( - _("Can't retrieve {full_jid} infos, ignoring") - .format(full_jid=full_jid.full())) - continue - if infos.features.issuperset(namespaces): - if identities is not None and not set( - infos.identities.keys() - ).issuperset(identities): + for idx, (success, infos) in enumerate(infos_data): + full_jid = full_jids[idx] + if not success: + log.warning( + _("Can't retrieve {full_jid} infos, ignoring") + .format(full_jid=full_jid.full())) continue - found_identities = [ - (cat, type_, name or "") - for (cat, type_), name in infos.identities.items() - ] - found[full_jid.full()] = found_identities + if infos.features.issuperset(namespaces): + if identities is not None and not set( + infos.identities.keys() + ).issuperset(identities): + continue + found_identities = [ + (cat, type_, name or "") + for (cat, type_), name in infos.identities.items() + ] + found[full_jid.full()] = found_identities - defer.returnValue((found_service, found_own, found_roster)) + return (found_service, found_own, found_roster) ## Generic HMI ##
--- a/sat/plugins/plugin_adhoc_dbus.py Wed Jan 29 11:19:47 2020 +0100 +++ b/sat/plugins/plugin_adhoc_dbus.py Wed Jan 29 12:38:48 2020 +0100 @@ -329,9 +329,9 @@ - device name - device label """ - found_data = yield self.host.findByFeatures( + found_data = yield defer.ensureDeferred(self.host.findByFeatures( client, [self.host.ns_map['commands']], service=False, roster=False, - own_jid=True, local_device=True) + own_jid=True, local_device=True)) remotes = []