# HG changeset patch # User Goffi # Date 1535722165 -7200 # Node ID bc122b68eacd2b1cf1ae9a88f95394ebeecd0693 # Parent 20bf6887d1ed79822070054afb8fc04c3e7ff10d core: findByFeatures fixes diff -r 20bf6887d1ed -r bc122b68eacd sat/core/sat_main.py --- a/sat/core/sat_main.py Fri Aug 31 15:25:25 2018 +0200 +++ b/sat/core/sat_main.py Fri Aug 31 15:29:25 2018 +0200 @@ -811,41 +811,15 @@ def findFeaturesSet(self, *args, **kwargs): return self.memory.disco.findFeaturesSet(*args, **kwargs) - def _findByFeatures( - self, - namespaces, - identities, - bare_jids, - service, - roster, - own_jid, - local_device, - profile_key, - ): + 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 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, - ): + 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 @@ -865,6 +839,7 @@ - own entities - roster entities """ + assert isinstance(namespaces, list) if not identities: identities = None if not namespaces and not identities: @@ -888,16 +863,13 @@ ] found_service[service_jid.full()] = found_identities - jids = [] - if roster: - jids.extend(client.roster.getJids()) + to_find = [] if own_jid: - jids.append(client.jid.userhostJID()) + to_find.append((found_own, [client.jid.userhostJID()])) + if roster: + to_find.append((found_roster, client.roster.getJids())) - for found, jids in ( - (found_own, [client.jid.userhostJID()]), - (found_roster, client.roster.getJids()), - ): + for found, jids in to_find: for jid_ in jids: if jid_.resource: if bare_jids: @@ -911,6 +883,11 @@ resources = self.memory.getAvailableResources(client, jid_) except exceptions.UnknownEntityError: continue + if not resources and jid_ == client.jid.userhostJID() and own_jid: + # small hack to avoid missing our own resource when this + # method is called at the very beginning of the session + # and our presence has not been received yet + resources = [client.jid.resource] for resource in resources: full_jid = jid.JID(tuple=(jid_.user, jid_.host, resource)) if full_jid == client.jid and not local_device: