Mercurial > libervia-backend
changeset 467:47af60767013
plugin group blog: getMassiveGroupBlog first draft
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 29 Mar 2012 00:04:31 +0200 |
parents | 448ce3c9e2ac |
children | c97640c90a94 |
files | src/core/xmpp.py src/plugins/plugin_misc_groupblog.py |
diffstat | 2 files changed, 64 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/core/xmpp.py Mon Mar 26 00:22:49 2012 +0200 +++ b/src/core/xmpp.py Thu Mar 29 00:04:31 2012 +0200 @@ -224,9 +224,13 @@ @return: RosterItem or None if contact is not in cache""" return self._jids.get(jid.userhost(), None) + def getBareJids(self): + """Return all bare jids (as unicode) of the roster""" + return self._jids.keys() + def getItems(self): """Return all items of the roster""" - return self._jids + return self._jids.values() class SatPresenceProtocol(xmppim.PresenceClientProtocol):
--- a/src/plugins/plugin_misc_groupblog.py Mon Mar 26 00:22:49 2012 +0200 +++ b/src/plugins/plugin_misc_groupblog.py Thu Mar 29 00:04:31 2012 +0200 @@ -87,6 +87,12 @@ 'param_2':'%(doc_profile)s', 'return':'list of microblog data (dict)' }) + + host.bridge.addMethod("getMassiveLastGroupBlogs", ".plugin", + in_sign='sasis', out_sign='a{saa{ss}}', + method=self.getMassiveLastGroupBlogs, + async = True) + @defer.inlineCallbacks def initialise(self, profile_key): @@ -117,7 +123,7 @@ client.item_access_pubsub = entity if not client.item_access_pubsub: - error(_("No item-access powered pubsub server found, can't post group blog")) + error(_("No item-access powered pubsub server found, can't use group blog")) raise NoCompatiblePubSubServerFound defer.returnValue((profile, client)) @@ -180,3 +186,55 @@ self.initialise(profile_key).addCallback(initialised) #TODO: we need to use the server corresponding the the host of the jid + def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@DEFAULT@', callback=None, errback=None): + """Get the last published microblogs for a list of groups or jids + @param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL") + @param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids) + @param max_items: how many microblogs we want to get + @param profile_key: profile key + @param callback: used for the async answer + @param errback: used for the async answer + """ + def sendResult(result): + """send result of DeferredList (list of microblogs to the calling method""" + + ret = {} + + for (success, value) in result: + if success: + source_jid, data = value + ret[source_jid] = data + + callback(ret) + + def initialised(result): + profile, client = result + + if publishers_type == "ALL": + contacts = client.roster.getItems() + print "contacts:", contacts + jids = [contact.jid.userhost() for contact in contacts] + print "jids:", jids + mblogs = [] + for _jid in jids: + d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, jid.JID(_jid).userhost(), + max_items=max_items, profile_key=profile_key) + #TODO: check empty result (nothing published so far) + d.addCallback(lambda items, source_jid: (source_jid, map(self.host.plugins["XEP-0277"].item2mbdata, items)), _jid) + mblogs.append(d) + dlist = defer.DeferredList(mblogs) + dlist.addCallback(sendResult) + + #d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, jid.JID(pub_jid).userhost(), + # max_items=max_items, profile_key=profile_key) + #d.addCallbacks(lambda items: callback(map(self.host.plugins["XEP-0277"].item2mbdata, items)), errback) + + assert(callback) + #TODO: custom exception + if publishers_type not in ["GROUP", "JID", "ALL"]: + raise Exception("Bad call, unknown publishers_type") + if publishers_type=="ALL" and publishers: + raise Exception("Publishers list must be empty when getting microblogs for all contacts") + return self.initialise(profile_key).addCallback(initialised) + #TODO: we need to use the server corresponding the the host of the jid +