comparison sat/core/sat_main.py @ 2666:bc122b68eacd

core: findByFeatures fixes
author Goffi <goffi@goffi.org>
date Fri, 31 Aug 2018 15:29:25 +0200
parents 4e130cc9bfc0
children e9cd473a2f46
comparison
equal deleted inserted replaced
2665:20bf6887d1ed 2666:bc122b68eacd
809 return self.memory.disco.findServiceEntities(*args, **kwargs) 809 return self.memory.disco.findServiceEntities(*args, **kwargs)
810 810
811 def findFeaturesSet(self, *args, **kwargs): 811 def findFeaturesSet(self, *args, **kwargs):
812 return self.memory.disco.findFeaturesSet(*args, **kwargs) 812 return self.memory.disco.findFeaturesSet(*args, **kwargs)
813 813
814 def _findByFeatures( 814 def _findByFeatures(self, namespaces, identities, bare_jids, service, roster, own_jid,
815 self, 815 local_device, profile_key):
816 namespaces,
817 identities,
818 bare_jids,
819 service,
820 roster,
821 own_jid,
822 local_device,
823 profile_key,
824 ):
825 client = self.getClient(profile_key) 816 client = self.getClient(profile_key)
826 return self.findByFeatures( 817 return self.findByFeatures(client, namespaces, identities, bare_jids, service,
827 client, 818 roster, own_jid, local_device,)
828 namespaces,
829 identities,
830 bare_jids,
831 service,
832 roster,
833 own_jid,
834 local_device,
835 )
836 819
837 @defer.inlineCallbacks 820 @defer.inlineCallbacks
838 def findByFeatures( 821 def findByFeatures(self, client, namespaces, identities=None, bare_jids=False,
839 self, 822 service=True, roster=True, own_jid=True, local_device=False):
840 client,
841 namespaces,
842 identities=None,
843 bare_jids=False,
844 service=True,
845 roster=True,
846 own_jid=True,
847 local_device=False,
848 ):
849 """retrieve all services or contacts managing a set a features 823 """retrieve all services or contacts managing a set a features
850 824
851 @param namespaces(list[unicode]): features which must be handled 825 @param namespaces(list[unicode]): features which must be handled
852 @param identities(list[tuple[unicode,unicode]], None): if not None or empty, 826 @param identities(list[tuple[unicode,unicode]], None): if not None or empty,
853 only keep those identities tuple must by (category, type) 827 only keep those identities tuple must by (category, type)
863 entities in a tuple with: 837 entities in a tuple with:
864 - service entities 838 - service entities
865 - own entities 839 - own entities
866 - roster entities 840 - roster entities
867 """ 841 """
842 assert isinstance(namespaces, list)
868 if not identities: 843 if not identities:
869 identities = None 844 identities = None
870 if not namespaces and not identities: 845 if not namespaces and not identities:
871 raise exceptions.DataError( 846 raise exceptions.DataError(
872 "at least one namespace or one identity must be set" 847 "at least one namespace or one identity must be set"
886 (cat, type_, name or u"") 861 (cat, type_, name or u"")
887 for (cat, type_), name in infos.identities.iteritems() 862 for (cat, type_), name in infos.identities.iteritems()
888 ] 863 ]
889 found_service[service_jid.full()] = found_identities 864 found_service[service_jid.full()] = found_identities
890 865
891 jids = [] 866 to_find = []
867 if own_jid:
868 to_find.append((found_own, [client.jid.userhostJID()]))
892 if roster: 869 if roster:
893 jids.extend(client.roster.getJids()) 870 to_find.append((found_roster, client.roster.getJids()))
894 if own_jid: 871
895 jids.append(client.jid.userhostJID()) 872 for found, jids in to_find:
896
897 for found, jids in (
898 (found_own, [client.jid.userhostJID()]),
899 (found_roster, client.roster.getJids()),
900 ):
901 for jid_ in jids: 873 for jid_ in jids:
902 if jid_.resource: 874 if jid_.resource:
903 if bare_jids: 875 if bare_jids:
904 continue 876 continue
905 resources = [jid_.resource] 877 resources = [jid_.resource]
909 else: 881 else:
910 try: 882 try:
911 resources = self.memory.getAvailableResources(client, jid_) 883 resources = self.memory.getAvailableResources(client, jid_)
912 except exceptions.UnknownEntityError: 884 except exceptions.UnknownEntityError:
913 continue 885 continue
886 if not resources and jid_ == client.jid.userhostJID() and own_jid:
887 # small hack to avoid missing our own resource when this
888 # method is called at the very beginning of the session
889 # and our presence has not been received yet
890 resources = [client.jid.resource]
914 for resource in resources: 891 for resource in resources:
915 full_jid = jid.JID(tuple=(jid_.user, jid_.host, resource)) 892 full_jid = jid.JID(tuple=(jid_.user, jid_.host, resource))
916 if full_jid == client.jid and not local_device: 893 if full_jid == client.jid and not local_device:
917 continue 894 continue
918 infos = yield self.getDiscoInfos(client, full_jid) 895 infos = yield self.getDiscoInfos(client, full_jid)