Mercurial > libervia-backend
diff src/plugins/plugin_xep_0060.py @ 1268:bb30bf3ae932
plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 15 Dec 2014 14:04:19 +0100 |
parents | ea692d51a0ee |
children | 74d558e6c9fd |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0060.py Mon Dec 15 14:03:13 2014 +0100 +++ b/src/plugins/plugin_xep_0060.py Mon Dec 15 14:04:19 2014 +0100 @@ -26,6 +26,7 @@ from wokkel import disco, pubsub, rsm from zope.interface import implements from twisted.internet import defer +import uuid PLUGIN_INFO = { @@ -154,21 +155,41 @@ profile, client = self.__getClientNProfile(profile_key, 'publish item') return client.publish(service, nodeIdentifier, items, client.parent.jid) - def getItems(self, service, node, max_items=None, item_ids=None, sub_id=None, profile_key=C.PROF_KEY_NONE): + def getItems(self, service, node, max_items=None, item_ids=None, sub_id=None, rsm=None, profile_key=C.PROF_KEY_NONE): + """Retrieve pubsub items from a node. + + @param service (JID): target service. + @param node (str): node id. + @param max_items (int): optional limit on the number of retrieved items. + @param item_ids (list[str]): identifiers of the items to be retrieved (should not be used). + @param sub_id (str): optional subscription identifier. + @param rsm (dict): RSM request data + @param profile_key (str): %(doc_profile_key)s + @return: a deferred couple (list[dict], dict) containing: + - list of items + - RSM response data + """ profile, client = self.__getClientNProfile(profile_key, 'get items') - return client.items(service, node, max_items, item_ids, sub_id, client.parent.jid) + ext_data = {'id': unicode(uuid.uuid4()), 'rsm': rsm} if rsm else None + d = client.items(service, node, max_items, item_ids, sub_id, client.parent.jid, ext_data) + d.addCallback(lambda items: (items, client.getRSMResponse(ext_data['id']) if rsm else {})) + return d @defer.inlineCallbacks - def getItemsFromMany(self, service, data, max_items=None, item_ids=None, sub_id=None, profile_key=C.PROF_KEY_NONE): + 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*. - @param item_ids (list[str]): identifiers of the items to be retrieved (should not be used). @param sub_id (str): optional subscription identifier. + @param rsm (dict): RSM request data @param profile_key (str): %(doc_profile_key)s - @return: dict binding a subset of the keys of data to Deferred instances. + @return: a deferred dict with: + - key: a value in (a subset of) data.keys() + - couple (list[dict], dict) containing: + - list of items + - RSM response data """ profile, client = self.__getClientNProfile(profile_key, 'get items') found_nodes = yield self.listNodes(service, profile=profile) @@ -177,7 +198,7 @@ if node not in found_nodes: log.debug("Skip the items retrieval for [{node}]: node doesn't exist".format(node=node)) continue # avoid pubsub "item-not-found" error - d_dict[publisher] = client.items(service, node, max_items, item_ids, sub_id, client.parent.jid) + d_dict[publisher] = self.getItems(service, node, max_items, None, sub_id, rsm, profile) defer.returnValue(d_dict) def getOptions(self, service, nodeIdentifier, subscriber, subscriptionIdentifier=None, profile_key=C.PROF_KEY_NONE):