comparison src/plugins/plugin_misc_groupblog.py @ 892:58107179cd97

plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
author souliane <souliane@mailoo.org>
date Fri, 28 Feb 2014 11:19:08 +0100
parents a7b2aacf22ac
children 1a759096ccbd
comparison
equal deleted inserted replaced
891:a7b2aacf22ac 892:58107179cd97
102 async=True) 102 async=True)
103 103
104 host.bridge.addMethod("getGroupBlogs", ".plugin", 104 host.bridge.addMethod("getGroupBlogs", ".plugin",
105 in_sign='sass', out_sign='aa{ss}', 105 in_sign='sass', out_sign='aa{ss}',
106 method=self.getGroupBlogs, 106 method=self.getGroupBlogs,
107 async=True)
108
109 host.bridge.addMethod("getGroupBlogsWithComments", ".plugin",
110 in_sign='sass', out_sign='a(a{ss}aa{ss})',
111 method=self.getGroupBlogsWithComments,
107 async=True) 112 async=True)
108 113
109 host.bridge.addMethod("getLastGroupBlogs", ".plugin", 114 host.bridge.addMethod("getLastGroupBlogs", ".plugin",
110 in_sign='sis', out_sign='aa{ss}', 115 in_sign='sis', out_sign='aa{ss}',
111 method=self.getLastGroupBlogs, 116 method=self.getLastGroupBlogs,
539 @param profile_key: profile key 544 @param profile_key: profile key
540 @return: list of microblog data (dict) 545 @return: list of microblog data (dict)
541 """ 546 """
542 return self.__getGroupBlogs(pub_jid_s, item_ids=item_ids, profile_key=profile_key) 547 return self.__getGroupBlogs(pub_jid_s, item_ids=item_ids, profile_key=profile_key)
543 548
549 def getGroupBlogsWithComments(self, pub_jid_s, item_ids=None, profile_key='@NONE@'):
550 """Get the published microblogs of the specified IDs and their comments. If
551 item_ids is None, returns the last published microblogs and their comments.
552 @param pub_jid_s: jid of the publisher
553 @param item_ids: list of microblogs items IDs
554 @param profile_key: profile key
555 @return: list of couple (microblog data, list of microblog data)
556 """
557 def get_comments(data):
558 d_list = []
559 for entry in data:
560 if entry.get('comments', False):
561 d = self.getGroupBlogComments(entry['comments_service'], entry['comments_node'], profile_key=profile_key)
562 d.addCallback(lambda data: (entry, data))
563 d_list.append(d)
564 else:
565 d_list.append(defer.succeed((entry, [])))
566 deferred_list = defer.DeferredList(d_list)
567 deferred_list.addCallback(lambda result: [value for (success, value) in result if success])
568 return deferred_list
569
570 d = self.__getGroupBlogs(pub_jid_s, item_ids=item_ids, profile_key=profile_key)
571 d.addCallback(get_comments)
572 return d
573
574
544 def getLastGroupBlogs(self, pub_jid_s, max_items=10, profile_key='@NONE@'): 575 def getLastGroupBlogs(self, pub_jid_s, max_items=10, profile_key='@NONE@'):
545 """Get the last published microblogs 576 """Get the last published microblogs
546 @param pub_jid_s: jid of the publisher 577 @param pub_jid_s: jid of the publisher
547 @param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7) 578 @param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7)
548 @param profile_key: profile key 579 @param profile_key: profile key