Mercurial > libervia-backend
diff src/plugins/plugin_misc_groupblog.py @ 1233:0b87d029f0a3
plugin XEP-0277, groupblog: fixes namespace issue of the items that are received from an event + trap some errors
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 06 Oct 2014 17:25:41 +0200 |
parents | 318eab3f93f8 |
children | b4a264915ea9 |
line wrap: on
line diff
--- a/src/plugins/plugin_misc_groupblog.py Tue Oct 07 10:19:01 2014 +0200 +++ b/src/plugins/plugin_misc_groupblog.py Mon Oct 06 17:25:41 2014 +0200 @@ -212,25 +212,27 @@ return False return True - @defer.inlineCallbacks def _handleCommentsItems(self, items, service, node_identifier): """ Convert comments items to groupblog data, and send them as signals @param items: comments items @param service: jid of the PubSub service used @param node_identifier: comments node - @return: list of group blog data + @return: deferred list of group blog data """ - ret = [] - for item in items: + d_list = [] + + def cb(microblog_data): publisher = "" # FIXME: publisher attribute for item in SàT pubsub is not managed yet, so # publisher is not checked and can be easily spoofed. This need to be fixed # quickly. - microblog_data = yield self.item2gbdata(item, "comment") microblog_data["service"] = service.userhost() microblog_data["node"] = node_identifier microblog_data["verified_publisher"] = "true" if publisher else "false" - ret.append(microblog_data) - defer.returnValue(ret) + return microblog_data + + for item in items: + d_list.append(self.item2gbdata(item, "comment").addCallback(cb)) + return defer.DeferredList(d_list, consumeErrors=True).addCallback(lambda result: [value for (success, value) in result if success]) def _parseAccessData(self, microblog_data, item): P = self.host.plugins["XEP-0060"] @@ -477,8 +479,6 @@ return self._initialise(profile_key).addCallback(initialised) - - @defer.inlineCallbacks def _itemsConstruction(self, items, pub_jid, client): """ Transforms items to group blog data and manage comments node @@ -487,29 +487,33 @@ @param client: SatXMPPClient instance @return: deferred which fire list of group blog data """ # TODO: use items data when pub_jid is None - ret = [] - for item in items: - gbdata = yield self.item2gbdata(item) + d_list = [] + + @defer.inlineCallbacks + def cb(gbdata): try: gbdata['service'] = client.item_access_pubsub.full() except AttributeError: - pass - ret.append(gbdata) + log.warning(_("Pubsub service is unknown for blog entry %s") % gbdata['id']) # every comments node must be subscribed, except if we are the publisher (we are already subscribed in this case) if "comments_node" in gbdata and pub_jid.userhostJID() != client.jid.userhostJID(): try: service = jid.JID(gbdata["comments_service"]) node = gbdata["comments_node"] except KeyError: - log.warning("Missing key for comments") - continue + log.error(_("Missing key for blog comment %s") % gbdata['id']) + defer.returnValue(gbdata) # TODO: see if it is really needed to check for not subscribing twice to the node # It previously worked without this check, but the pubsub service logs were polluted # or, if in debug mode, it made sat-pubsub very difficult to debug. subscribed_nodes = yield self.host.plugins['XEP-0060'].listSubscribedNodes(service, profile=client.profile) if node not in subscribed_nodes: # avoid sat-pubsub "SubscriptionExists" error self.host.plugins["XEP-0060"].subscribe(service, node, profile_key=client.profile) - defer.returnValue(ret) + defer.returnValue(gbdata) + + for item in items: + d_list.append(self.item2gbdata(item).addCallback(cb)) + return defer.DeferredList(d_list, consumeErrors=True).addCallback(lambda result: [value for (success, value) in result if success]) def __getGroupBlogs(self, pub_jid_s, max_items=10, item_ids=None, profile_key=C.PROF_KEY_NONE): """Retrieve previously published items from a publish subscribe node.