# HG changeset patch # User souliane # Date 1393582748 -3600 # Node ID 58107179cd97c993bbbc0404537048d54574fa23 # Parent a7b2aacf22ac336f0dc641d50a84633b5a43e0ec plugin groupblog: added a convenient bridge method getGroupBlogsWithComments diff -r a7b2aacf22ac -r 58107179cd97 src/plugins/plugin_misc_groupblog.py --- a/src/plugins/plugin_misc_groupblog.py Tue Feb 25 17:49:15 2014 +0100 +++ b/src/plugins/plugin_misc_groupblog.py Fri Feb 28 11:19:08 2014 +0100 @@ -106,6 +106,11 @@ 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 @@ """ 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