diff src/plugins/plugin_xep_0060.py @ 2360:72cbb6478f97

plugin XEP-0060: use client instead of profile_key in getItems
author Goffi <goffi@goffi.org>
date Sun, 24 Sep 2017 16:32:22 +0200
parents 6c26f435a02d
children 5675af905725
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0060.py	Sun Sep 24 16:29:18 2017 +0200
+++ b/src/plugins/plugin_xep_0060.py	Sun Sep 24 16:32:22 2017 +0200
@@ -317,14 +317,15 @@
 
         @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit
         """
+        client = self.host.getClient(profile_key)
         service = jid.JID(service) if service else None
         max_items = None if max_items == C.NO_LIMIT else max_items
         extra = self.parseExtra(extra_dict)
-        d = self.getItems(service, node or None, max_items or None, item_ids, sub_id or None, extra.rsm_request, extra.extra, profile_key)
+        d = self.getItems(client, service, node or None, max_items or None, item_ids, sub_id or None, extra.rsm_request, extra.extra)
         d.addCallback(self.serItemsData)
         return d
 
-    def getItems(self, service, node, max_items=None, item_ids=None, sub_id=None, rsm_request=None, extra=None, profile_key=C.PROF_KEY_NONE):
+    def getItems(self, client, service, node, max_items=None, item_ids=None, sub_id=None, rsm_request=None, extra=None):
         """Retrieve pubsub items from a node.
 
         @param service (JID, None): pubsub service.
@@ -333,7 +334,6 @@
         @param item_ids (list[str]): identifiers of the items to be retrieved (can't be used with rsm_request).
         @param sub_id (str): optional subscription identifier.
         @param rsm_request (rsm.RSMRequest): RSM request data
-        @param profile_key (unicode): %(doc_profile_key)s
         @return: a deferred couple (list[dict], dict) containing:
             - list of items
             - metadata with the following keys:
@@ -346,7 +346,6 @@
             raise ValueError(u"items_id can't be used with rsm")
         if extra is None:
             extra = {}
-        client = self.host.getClient(profile_key)
         try:
             mam_query = extra['mam']
         except KeyError:
@@ -380,7 +379,7 @@
             log.warning(u"Could not subscribe to node {} on service {}: {}".format(node, unicode(service), unicode(failure.value)))
 
         def doSubscribe(items):
-            self.subscribe(service, node, profile_key=profile_key).addErrback(subscribeEb, service, node)
+            self.subscribe(service, node, profile_key=client.profile_key).addErrback(subscribeEb, service, node)
             return items
 
         if subscribe:
@@ -403,7 +402,6 @@
     # @defer.inlineCallbacks
     # def getItemsFromMany(self, service, data, max_items=None, sub_id=None, rsm=None, profile_key=C.PROF_KEY_NONE):
     #     """Massively retrieve pubsub items from many nodes.
-
     #     @param service (JID): target service.
     #     @param data (dict): dictionnary binding some arbitrary keys to the node identifiers.
     #     @param max_items (int): optional limit on the number of retrieved items *per node*.
@@ -854,7 +852,7 @@
         client = self.host.getClient(profile_key)
         deferreds = {}
         for service, node in node_data:
-            deferreds[(service, node)] = self.getItems(service, node, max_item, rsm_request=rsm_request, extra=extra, profile_key=profile_key)
+            deferreds[(service, node)] = self.getItems(client, service, node, max_item, rsm_request=rsm_request, extra=extra)
         return self.rt_sessions.newSession(deferreds, client.profile)