changeset 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 47516e90d26a
children 5defafc8ede6
files src/plugins/plugin_exp_events.py src/plugins/plugin_xep_0060.py src/plugins/plugin_xep_0277.py
diffstat 3 files changed, 13 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_exp_events.py	Sun Sep 24 16:29:18 2017 +0200
+++ b/src/plugins/plugin_exp_events.py	Sun Sep 24 16:32:22 2017 +0200
@@ -104,7 +104,7 @@
         """
         if not id_:
             id_ = NS_EVENT
-        items, metadata = yield self._p.getItems(service, node, item_ids=[id_], profile_key=client.profile)
+        items, metadata = yield self._p.getItems(client, service, node, item_ids=[id_])
         try:
             event_elt = next(items[0].elements(NS_EVENT, u'event'))
         except IndexError:
@@ -285,7 +285,7 @@
         @return (dict): a dict with current attendance status,
             an empty dict is returned if nothing has been answered yed
         """
-        items, metadata = yield self._p.getItems(service, node, item_ids=[client.jid.userhost()], profile_key=client.profile)
+        items, metadata = yield self._p.getItems(client, service, node, item_ids=[client.jid.userhost()])
         try:
             event_elt = next(items[0].elements(NS_EVENT, u'invitee'))
         except IndexError:
@@ -339,7 +339,7 @@
         @return (dict): a dict with current attendance status,
             an empty dict is returned if nothing has been answered yed
         """
-        items, metadata = yield self._p.getItems(service, node, profile_key=client.profile)
+        items, metadata = yield self._p.getItems(client, service, node)
         invitees = {}
         for item in items:
             try:
--- 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)
 
 
--- a/src/plugins/plugin_xep_0277.py	Sun Sep 24 16:29:18 2017 +0200
+++ b/src/plugins/plugin_xep_0277.py	Sun Sep 24 16:32:22 2017 +0200
@@ -630,7 +630,7 @@
         """
         if node is None:
             node = NS_MICROBLOG
-        items_data = yield self._p.getItems(service, node, max_items=max_items, item_ids=item_ids, rsm_request=rsm_request, extra=extra, profile_key=client.profile)
+        items_data = yield self._p.getItems(client, service, node, max_items=max_items, item_ids=item_ids, rsm_request=rsm_request, extra=extra)
         serialised = yield self._p.serItemsDataD(items_data, self.item2mbdata)
         defer.returnValue(serialised)
 
@@ -892,6 +892,8 @@
         #      to serialise and associate the data, but it make life in frontends side
         #      a lot easier
 
+        client, node_data = self._getClientAndNodeData(publishers_type, publishers, profile_key)
+
         def getComments(items_data):
             """Retrieve comments and add them to the items_data
 
@@ -910,7 +912,7 @@
                         service_s = value
                         node = item["{}{}".format(prefix, "_node")]
                         # time to get the comments
-                        d = self._p.getItems(jid.JID(service_s), node, max_comments, rsm_request=rsm_comments, extra=extra_comments, profile_key=profile_key)
+                        d = self._p.getItems(client, jid.JID(service_s), node, max_comments, rsm_request=rsm_comments, extra=extra_comments)
                         # then serialise
                         d.addCallback(lambda items_data: self._p.serItemsDataD(items_data, self.item2mbdata))
                         # with failure handling
@@ -930,10 +932,9 @@
             items_d.addCallback(lambda items_completed: (items_completed, metadata))
             return items_d
 
-        client, node_data = self._getClientAndNodeData(publishers_type, publishers, profile_key)
         deferreds = {}
         for service, node in node_data:
-            d = deferreds[(service, node)] = self._p.getItems(service, node, max_items, rsm_request=rsm_request, extra=extra, profile_key=profile_key)
+            d = deferreds[(service, node)] = self._p.getItems(client, service, node, max_items, rsm_request=rsm_request, extra=extra)
             d.addCallback(lambda items_data: self._p.serItemsDataD(items_data, self.item2mbdata))
             d.addCallback(getComments)
             d.addCallback(lambda items_comments_data: ('', items_comments_data))