plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)

This commit is contained in:
souliane 2014-12-15 14:04:19 +01:00
commit f3b7bd1ec2
3 changed files with 289 additions and 143 deletions

View file

@ -26,6 +26,7 @@ from sat.memory.memory import Sessions
from wokkel import disco, pubsub, rsm
from zope.interface import implements
from twisted.internet import defer
import uuid
PLUGIN_INFO = {
@ -154,21 +155,41 @@ class XEP_0060(object):
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 @@ class XEP_0060(object):
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):