plugin group blog: comments handling (comments are automaticaly requested when a comment node is found)
This commit is contained in:
parent
c9d23dd32b
commit
010651dd84
1 changed files with 30 additions and 14 deletions
|
|
@ -171,26 +171,37 @@ class GroupBlog(object):
|
||||||
warning("Host incoherence between %s and %s (hack attempt ?)" % (unicode(event.sender),
|
warning("Host incoherence between %s and %s (hack attempt ?)" % (unicode(event.sender),
|
||||||
unicode(publisher)))
|
unicode(publisher)))
|
||||||
return
|
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
|
return False
|
||||||
|
|
||||||
elif event.nodeIdentifier.startswith(NS_COMMENT_PREFIX):
|
elif event.nodeIdentifier.startswith(NS_COMMENT_PREFIX):
|
||||||
# Comment
|
# Comment
|
||||||
for item in event.items:
|
self._handleCommentsItems(event.items, event.sender, event.nodeIdentifier, profile)
|
||||||
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)
|
|
||||||
return False
|
return False
|
||||||
return True
|
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):
|
def _parseAccessData(self, microblog_data, item):
|
||||||
P = self.host.plugins["XEP-0060"]
|
P = self.host.plugins["XEP-0060"]
|
||||||
form_elts = filter(lambda elt: elt.name == "x", item.children)
|
form_elts = filter(lambda elt: elt.name == "x", item.children)
|
||||||
|
|
@ -333,6 +344,8 @@ class GroupBlog(object):
|
||||||
def _itemsConstruction(self, items, pub_jid, client):
|
def _itemsConstruction(self, items, pub_jid, client):
|
||||||
""" Transforms items to group blog data and manage comments node
|
""" Transforms items to group blog data and manage comments node
|
||||||
@param items: iterable of items
|
@param items: iterable of items
|
||||||
|
@param pub_jib: jid of the publisher
|
||||||
|
@param client: SatXMPPClient instance
|
||||||
@return: list of group blog data """
|
@return: list of group blog data """
|
||||||
ret = []
|
ret = []
|
||||||
for item in items:
|
for item in items:
|
||||||
|
|
@ -341,9 +354,12 @@ class GroupBlog(object):
|
||||||
# if there is a comments node, we subscribe to it
|
# if there is a comments node, we subscribe to it
|
||||||
if "comments_node" in gbdata and pub_jid.userhostJID() != client.jid.userhostJID():
|
if "comments_node" in gbdata and pub_jid.userhostJID() != client.jid.userhostJID():
|
||||||
try:
|
try:
|
||||||
|
# every comments node must be subscribed
|
||||||
self.host.plugins["XEP-0060"].subscribe(jid.JID(gbdata["comments_service"]), gbdata["comments_node"],
|
self.host.plugins["XEP-0060"].subscribe(jid.JID(gbdata["comments_service"]), gbdata["comments_node"],
|
||||||
profile_key=client.profile)
|
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:
|
except KeyError:
|
||||||
warning("Missing key for comments")
|
warning("Missing key for comments")
|
||||||
return ret
|
return ret
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue