plugin group blog: comments handling (comments are automaticaly requested when a comment node is found)

This commit is contained in:
Goffi 2013-06-17 13:17:43 +02:00
commit 010651dd84

View file

@ -171,26 +171,37 @@ class GroupBlog(object):
warning("Host incoherence between %s and %s (hack attempt ?)" % (unicode(event.sender),
unicode(publisher)))
return
for item in event.items:
microblog_data = self.item2gbdata(item)
self.host.bridge.personalEvent(publisher.full(), "MICROBLOG", microblog_data, profile)
client = self.host.getClient(profile)
for gbdata in self._itemsConstruction(event.items, publisher, client):
self.host.bridge.personalEvent(publisher.full(), "MICROBLOG", gbdata, profile)
return False
elif event.nodeIdentifier.startswith(NS_COMMENT_PREFIX):
# Comment
for item in event.items:
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 = self.item2gbdata(item, "comment")
microblog_data["service"] = event.sender.userhost()
microblog_data["node"] = event.nodeIdentifier
microblog_data["verified_publisher"] = "true" if publisher else "false"
self.host.bridge.personalEvent(publisher.full() if publisher else microblog_data["author"], "MICROBLOG", microblog_data, profile)
self._handleCommentsItems(event.items, event.sender, event.nodeIdentifier, profile)
return False
return True
def _handleCommentsItems(self, items, service, node_identifier, profile):
""" 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
@param profile: %(doc_profile)s
"""
for item in items:
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 = self.item2gbdata(item, "comment")
microblog_data["service"] = service.userhost()
microblog_data["node"] = node_identifier
microblog_data["verified_publisher"] = "true" if publisher else "false"
self.host.bridge.personalEvent(publisher.full() if publisher else microblog_data["author"], "MICROBLOG", microblog_data, profile)
def _parseAccessData(self, microblog_data, item):
P = self.host.plugins["XEP-0060"]
form_elts = filter(lambda elt: elt.name == "x", item.children)
@ -333,6 +344,8 @@ class GroupBlog(object):
def _itemsConstruction(self, items, pub_jid, client):
""" Transforms items to group blog data and manage comments node
@param items: iterable of items
@param pub_jib: jid of the publisher
@param client: SatXMPPClient instance
@return: list of group blog data """
ret = []
for item in items:
@ -341,9 +354,12 @@ class GroupBlog(object):
# if there is a comments node, we subscribe to it
if "comments_node" in gbdata and pub_jid.userhostJID() != client.jid.userhostJID():
try:
# every comments node must be subscribed
self.host.plugins["XEP-0060"].subscribe(jid.JID(gbdata["comments_service"]), gbdata["comments_node"],
profile_key=client.profile)
self.host.plugins["XEP-0060"].getItems(jid.JID(gbdata["comments_service"]), gbdata["comments_node"], profile_key=client.profile)
# we get all comments of the node, and handle them
defer_getItems = self.host.plugins["XEP-0060"].getItems(jid.JID(gbdata["comments_service"]), gbdata["comments_node"], profile_key=client.profile)
defer_getItems.addCallback(self._handleCommentsItems, jid.JID(gbdata["comments_service"]), gbdata["comments_node"], client.profile)
except KeyError:
warning("Missing key for comments")
return ret