changeset 2595:973d4551ffae

core: added local_device argument to discoFindByFeatures
author Goffi <goffi@goffi.org>
date Fri, 25 May 2018 10:52:01 +0200
parents 59ba387c17ea
children 93d64ce7a429
files sat/bridge/bridge_constructor/bridge_template.ini sat/bridge/dbus_bridge.py sat/core/sat_main.py sat_frontends/bridge/dbus_bridge.py sat_frontends/bridge/pb.py
diffstat 5 files changed, 18 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/sat/bridge/bridge_constructor/bridge_template.ini	Fri May 25 10:52:01 2018 +0200
+++ b/sat/bridge/bridge_constructor/bridge_template.ini	Fri May 25 10:52:01 2018 +0200
@@ -738,13 +738,14 @@
 async=
 type=method
 category=core
-sig_in=asa(ss)bbbbs
+sig_in=asa(ss)bbbbbs
 sig_out=(a{sa(sss)}a{sa(sss)}a{sa(sss)})
 param_2_default=False
 param_3_default=True
 param_4_default=True
 param_5_default=True
-param_6_default=u"@DEFAULT@"
+param_6_default=False
+param_7_default=u"@DEFAULT@"
 doc=Discover items of an entity
 doc_param_0=namespaces: namespaces of the features to check
 doc_param_1=identities: identities to filter
@@ -753,7 +754,8 @@
 doc_param_3=service: True to check server's services
 doc_param_4=roster: True to check connected devices from people in roster
 doc_param_5=own_jid: True to check profile's jid
-doc_param_6=%(doc_profile_key)s
+doc_param_6=local_device: True to check device on which the backend is running
+doc_param_7=%(doc_profile_key)s
 doc_return=tuple of maps of found entities full jids to their identities. Maps are in this order:
  - services entities
  - own entities (i.e. entities linked to profile's jid)
--- a/sat/bridge/dbus_bridge.py	Fri May 25 10:52:01 2018 +0200
+++ b/sat/bridge/dbus_bridge.py	Fri May 25 10:52:01 2018 +0200
@@ -234,10 +234,10 @@
         return self._callback("delContact", unicode(entity_jid), unicode(profile_key), callback=callback, errback=errback)
 
     @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
-                         in_signature='asa(ss)bbbbs', out_signature='(a{sa(sss)}a{sa(sss)}a{sa(sss)})',
+                         in_signature='asa(ss)bbbbbs', out_signature='(a{sa(sss)}a{sa(sss)}a{sa(sss)})',
                          async_callbacks=('callback', 'errback'))
-    def discoFindByFeatures(self, namespaces, identities, bare_jid=False, service=True, roster=True, own_jid=True, profile_key=u"@DEFAULT@", callback=None, errback=None):
-        return self._callback("discoFindByFeatures", namespaces, identities, bare_jid, service, roster, own_jid, unicode(profile_key), callback=callback, errback=errback)
+    def discoFindByFeatures(self, namespaces, identities, bare_jid=False, service=True, roster=True, own_jid=True, local_device=False, profile_key=u"@DEFAULT@", callback=None, errback=None):
+        return self._callback("discoFindByFeatures", namespaces, identities, bare_jid, service, roster, own_jid, local_device, unicode(profile_key), callback=callback, errback=errback)
 
     @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
                          in_signature='ssbs', out_signature='(asa(sss)a{sa(a{ss}as)})',
--- a/sat/core/sat_main.py	Fri May 25 10:52:01 2018 +0200
+++ b/sat/core/sat_main.py	Fri May 25 10:52:01 2018 +0200
@@ -671,12 +671,12 @@
     def findFeaturesSet(self, *args, **kwargs):
         return self.memory.disco.findFeaturesSet(*args, **kwargs)
 
-    def _findByFeatures(self, namespaces, identities, bare_jids, service, roster, own_jid, 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)
+        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):
+    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
@@ -688,6 +688,7 @@
         @param roster(bool): if True, return entities in roster
             full jid of all matching resources available will be returned
         @param own_jid(bool): if True, return profile's jid resources
+        @param local_device(bool): if True, return profile's jid local resource (i.e. client.jid)
         @return (tuple(dict[jid.JID(), tuple[unicode, unicode, unicode]]*3)): found entities in a tuple with:
             - service entities
             - own entities
@@ -732,6 +733,8 @@
                             continue
                 for resource in resources:
                     full_jid = jid.JID(tuple=(jid_.user, jid_.host, resource))
+                    if full_jid == client.jid and not local_device:
+                        continue
                     infos = yield self.getDiscoInfos(client, full_jid)
                     if infos.features.issuperset(namespaces):
                         if identities is not None and not set(infos.identities.keys()).issuperset(identities):
--- a/sat_frontends/bridge/dbus_bridge.py	Fri May 25 10:52:01 2018 +0200
+++ b/sat_frontends/bridge/dbus_bridge.py	Fri May 25 10:52:01 2018 +0200
@@ -209,14 +209,14 @@
             error_handler = lambda err:errback(dbus_to_bridge_exception(err))
         return self.db_core_iface.delContact(entity_jid, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
 
-    def discoFindByFeatures(self, namespaces, identities, bare_jid=False, service=True, roster=True, own_jid=True, profile_key=u"@DEFAULT@", callback=None, errback=None):
+    def discoFindByFeatures(self, namespaces, identities, bare_jid=False, service=True, roster=True, own_jid=True, local_device=False, profile_key=u"@DEFAULT@", callback=None, errback=None):
         if callback is None:
             error_handler = None
         else:
             if errback is None:
                 errback = log.error
             error_handler = lambda err:errback(dbus_to_bridge_exception(err))
-        return self.db_core_iface.discoFindByFeatures(namespaces, identities, bare_jid, service, roster, own_jid, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
+        return self.db_core_iface.discoFindByFeatures(namespaces, identities, bare_jid, service, roster, own_jid, local_device, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
 
     def discoInfos(self, entity_jid, node=u'', use_cache=True, profile_key=u"@DEFAULT@", callback=None, errback=None):
         if callback is None:
--- a/sat_frontends/bridge/pb.py	Fri May 25 10:52:01 2018 +0200
+++ b/sat_frontends/bridge/pb.py	Fri May 25 10:52:01 2018 +0200
@@ -180,8 +180,8 @@
             errback = self._generic_errback
         d.addErrback(errback)
 
-    def discoFindByFeatures(self, namespaces, identities, bare_jid=False, service=True, roster=True, own_jid=True, profile_key=u"@DEFAULT@", callback=None, errback=None):
-        d = self.root.callRemote("discoFindByFeatures", namespaces, identities, bare_jid, service, roster, own_jid, profile_key)
+    def discoFindByFeatures(self, namespaces, identities, bare_jid=False, service=True, roster=True, own_jid=True, local_device=False, profile_key=u"@DEFAULT@", callback=None, errback=None):
+        d = self.root.callRemote("discoFindByFeatures", namespaces, identities, bare_jid, service, roster, own_jid, local_device, profile_key)
         if callback is not None:
             d.addCallback(callback)
         if errback is None: