plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids

This commit is contained in:
souliane 2014-02-25 17:49:15 +01:00
commit 2b2fa9fd4a
2 changed files with 79 additions and 6 deletions

View file

@ -101,6 +101,11 @@ class GroupBlog(object):
method=self.sendGroupBlogComment,
async=True)
host.bridge.addMethod("getGroupBlogs", ".plugin",
in_sign='sass', out_sign='aa{ss}',
method=self.getGroupBlogs,
async=True)
host.bridge.addMethod("getLastGroupBlogs", ".plugin",
in_sign='sis', out_sign='aa{ss}',
method=self.getLastGroupBlogs,
@ -504,10 +509,11 @@ class GroupBlog(object):
warning("Missing key for comments")
defer.returnValue(ret)
def getLastGroupBlogs(self, pub_jid_s, max_items=10, profile_key='@NONE@'):
"""Get the last published microblogs
def __getGroupBlogs(self, pub_jid_s, max_items=10, item_ids=None, profile_key='@NONE@'):
"""Retrieve previously published items from a publish subscribe node.
@param pub_jid_s: jid of the publisher
@param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7)
@param item_ids: list of microblogs items IDs
@param profile_key: profile key
@return: list of microblog data (dict)
"""
@ -516,7 +522,7 @@ class GroupBlog(object):
def initialised(result):
profile, client = result
d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(pub_jid),
max_items=max_items, profile_key=profile_key)
max_items=max_items, item_ids=item_ids, profile_key=profile_key)
d.addCallback(self._itemsConstruction, pub_jid, client)
d.addErrback(lambda ignore: {}) # TODO: more complete error management (log !)
return d
@ -524,6 +530,26 @@ class GroupBlog(object):
#TODO: we need to use the server corresponding the the host of the jid
return self._initialise(profile_key).addCallback(initialised)
def getGroupBlogs(self, pub_jid_s, item_ids=None, profile_key='@NONE@'):
"""Get the published microblogs of the specified IDs. If item_ids is
None, the result would be the same than calling getLastGroupBlogs
with the default value for the attribute max_items.
@param pub_jid_s: jid of the publisher
@param item_ids: list of microblogs items IDs
@param profile_key: profile key
@return: list of microblog data (dict)
"""
return self.__getGroupBlogs(pub_jid_s, item_ids=item_ids, profile_key=profile_key)
def getLastGroupBlogs(self, pub_jid_s, max_items=10, profile_key='@NONE@'):
"""Get the last published microblogs
@param pub_jid_s: jid of the publisher
@param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7)
@param profile_key: profile key
@return: list of microblog data (dict)
"""
return self.__getGroupBlogs(pub_jid_s, max_items=max_items, profile_key=profile_key)
def getLastGroupBlogsAtom(self, pub_jid_s, max_items=10, profile_key='@NONE@'):
"""Get the atom feed of the last published microblogs
@param pub_jid: jid of the publisher