comparison src/plugins/plugin_misc_groupblog.py @ 891:a7b2aacf22ac

plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
author souliane <souliane@mailoo.org>
date Tue, 25 Feb 2014 17:49:15 +0100
parents 2b98f5631fba
children 58107179cd97
comparison
equal deleted inserted replaced
890:10bb8574ab11 891:a7b2aacf22ac
97 method=self.updateGroupBlog, 97 method=self.updateGroupBlog,
98 async=True) 98 async=True)
99 99
100 host.bridge.addMethod("sendGroupBlogComment", ".plugin", in_sign='ssa{ss}s', out_sign='', 100 host.bridge.addMethod("sendGroupBlogComment", ".plugin", in_sign='ssa{ss}s', out_sign='',
101 method=self.sendGroupBlogComment, 101 method=self.sendGroupBlogComment,
102 async=True)
103
104 host.bridge.addMethod("getGroupBlogs", ".plugin",
105 in_sign='sass', out_sign='aa{ss}',
106 method=self.getGroupBlogs,
102 async=True) 107 async=True)
103 108
104 host.bridge.addMethod("getLastGroupBlogs", ".plugin", 109 host.bridge.addMethod("getLastGroupBlogs", ".plugin",
105 in_sign='sis', out_sign='aa{ss}', 110 in_sign='sis', out_sign='aa{ss}',
106 method=self.getLastGroupBlogs, 111 method=self.getLastGroupBlogs,
502 profile_key=client.profile) 507 profile_key=client.profile)
503 except KeyError: 508 except KeyError:
504 warning("Missing key for comments") 509 warning("Missing key for comments")
505 defer.returnValue(ret) 510 defer.returnValue(ret)
506 511
512 def __getGroupBlogs(self, pub_jid_s, max_items=10, item_ids=None, profile_key='@NONE@'):
513 """Retrieve previously published items from a publish subscribe node.
514 @param pub_jid_s: jid of the publisher
515 @param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7)
516 @param item_ids: list of microblogs items IDs
517 @param profile_key: profile key
518 @return: list of microblog data (dict)
519 """
520 pub_jid = jid.JID(pub_jid_s)
521
522 def initialised(result):
523 profile, client = result
524 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(pub_jid),
525 max_items=max_items, item_ids=item_ids, profile_key=profile_key)
526 d.addCallback(self._itemsConstruction, pub_jid, client)
527 d.addErrback(lambda ignore: {}) # TODO: more complete error management (log !)
528 return d
529
530 #TODO: we need to use the server corresponding the the host of the jid
531 return self._initialise(profile_key).addCallback(initialised)
532
533 def getGroupBlogs(self, pub_jid_s, item_ids=None, profile_key='@NONE@'):
534 """Get the published microblogs of the specified IDs. If item_ids is
535 None, the result would be the same than calling getLastGroupBlogs
536 with the default value for the attribute max_items.
537 @param pub_jid_s: jid of the publisher
538 @param item_ids: list of microblogs items IDs
539 @param profile_key: profile key
540 @return: list of microblog data (dict)
541 """
542 return self.__getGroupBlogs(pub_jid_s, item_ids=item_ids, profile_key=profile_key)
543
507 def getLastGroupBlogs(self, pub_jid_s, max_items=10, profile_key='@NONE@'): 544 def getLastGroupBlogs(self, pub_jid_s, max_items=10, profile_key='@NONE@'):
508 """Get the last published microblogs 545 """Get the last published microblogs
509 @param pub_jid_s: jid of the publisher 546 @param pub_jid_s: jid of the publisher
510 @param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7) 547 @param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7)
511 @param profile_key: profile key 548 @param profile_key: profile key
512 @return: list of microblog data (dict) 549 @return: list of microblog data (dict)
513 """ 550 """
514 pub_jid = jid.JID(pub_jid_s) 551 return self.__getGroupBlogs(pub_jid_s, max_items=max_items, profile_key=profile_key)
515
516 def initialised(result):
517 profile, client = result
518 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(pub_jid),
519 max_items=max_items, profile_key=profile_key)
520 d.addCallback(self._itemsConstruction, pub_jid, client)
521 d.addErrback(lambda ignore: {}) # TODO: more complete error management (log !)
522 return d
523
524 #TODO: we need to use the server corresponding the the host of the jid
525 return self._initialise(profile_key).addCallback(initialised)
526 552
527 def getLastGroupBlogsAtom(self, pub_jid_s, max_items=10, profile_key='@NONE@'): 553 def getLastGroupBlogsAtom(self, pub_jid_s, max_items=10, profile_key='@NONE@'):
528 """Get the atom feed of the last published microblogs 554 """Get the atom feed of the last published microblogs
529 @param pub_jid: jid of the publisher 555 @param pub_jid: jid of the publisher
530 @param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7) 556 @param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7)