plugin groupblog: added a convenient bridge method getGroupBlogsWithComments

This commit is contained in:
souliane 2014-02-28 11:19:08 +01:00
commit 528ceb5f8b

View file

@ -106,6 +106,11 @@ class GroupBlog(object):
method=self.getGroupBlogs,
async=True)
host.bridge.addMethod("getGroupBlogsWithComments", ".plugin",
in_sign='sass', out_sign='a(a{ss}aa{ss})',
method=self.getGroupBlogsWithComments,
async=True)
host.bridge.addMethod("getLastGroupBlogs", ".plugin",
in_sign='sis', out_sign='aa{ss}',
method=self.getLastGroupBlogs,
@ -541,6 +546,32 @@ class GroupBlog(object):
"""
return self.__getGroupBlogs(pub_jid_s, item_ids=item_ids, profile_key=profile_key)
def getGroupBlogsWithComments(self, pub_jid_s, item_ids=None, profile_key='@NONE@'):
"""Get the published microblogs of the specified IDs and their comments. If
item_ids is None, returns the last published microblogs and their comments.
@param pub_jid_s: jid of the publisher
@param item_ids: list of microblogs items IDs
@param profile_key: profile key
@return: list of couple (microblog data, list of microblog data)
"""
def get_comments(data):
d_list = []
for entry in data:
if entry.get('comments', False):
d = self.getGroupBlogComments(entry['comments_service'], entry['comments_node'], profile_key=profile_key)
d.addCallback(lambda data: (entry, data))
d_list.append(d)
else:
d_list.append(defer.succeed((entry, [])))
deferred_list = defer.DeferredList(d_list)
deferred_list.addCallback(lambda result: [value for (success, value) in result if success])
return deferred_list
d = self.__getGroupBlogs(pub_jid_s, item_ids=item_ids, profile_key=profile_key)
d.addCallback(get_comments)
return d
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