Mercurial > libervia-backend
comparison src/plugins/plugin_misc_groupblog.py @ 617:dafdbe28ca2f
plugin group blog: comments handling (comments are automaticaly requested when a comment node is found)
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 17 Jun 2013 13:17:43 +0200 |
parents | 8782f94e761e |
children | e2c33a16d235 |
comparison
equal
deleted
inserted
replaced
616:8782f94e761e | 617:dafdbe28ca2f |
---|---|
169 or len(event_host) < len(origin_host) | 169 or len(event_host) < len(origin_host) |
170 or event_host[-len(origin_host):] != origin_host): | 170 or event_host[-len(origin_host):] != origin_host): |
171 warning("Host incoherence between %s and %s (hack attempt ?)" % (unicode(event.sender), | 171 warning("Host incoherence between %s and %s (hack attempt ?)" % (unicode(event.sender), |
172 unicode(publisher))) | 172 unicode(publisher))) |
173 return | 173 return |
174 for item in event.items: | 174 |
175 microblog_data = self.item2gbdata(item) | 175 client = self.host.getClient(profile) |
176 | 176 |
177 self.host.bridge.personalEvent(publisher.full(), "MICROBLOG", microblog_data, profile) | 177 for gbdata in self._itemsConstruction(event.items, publisher, client): |
178 self.host.bridge.personalEvent(publisher.full(), "MICROBLOG", gbdata, profile) | |
178 return False | 179 return False |
180 | |
179 elif event.nodeIdentifier.startswith(NS_COMMENT_PREFIX): | 181 elif event.nodeIdentifier.startswith(NS_COMMENT_PREFIX): |
180 # Comment | 182 # Comment |
181 for item in event.items: | 183 self._handleCommentsItems(event.items, event.sender, event.nodeIdentifier, profile) |
182 publisher = "" # FIXME: publisher attribute for item in SàT pubsub is not managed yet, so | |
183 # publisher is not checked and can be easily spoofed. This need to be fixed | |
184 # quickly. | |
185 microblog_data = self.item2gbdata(item, "comment") | |
186 microblog_data["service"] = event.sender.userhost() | |
187 microblog_data["node"] = event.nodeIdentifier | |
188 microblog_data["verified_publisher"] = "true" if publisher else "false" | |
189 | |
190 self.host.bridge.personalEvent(publisher.full() if publisher else microblog_data["author"], "MICROBLOG", microblog_data, profile) | |
191 return False | 184 return False |
192 return True | 185 return True |
186 | |
187 def _handleCommentsItems(self, items, service, node_identifier, profile): | |
188 """ Convert comments items to groupblog data, and send them as signals | |
189 @param items: comments items | |
190 @param service: jid of the PubSub service used | |
191 @param node_identifier: comments node | |
192 @param profile: %(doc_profile)s | |
193 """ | |
194 for item in items: | |
195 publisher = "" # FIXME: publisher attribute for item in SàT pubsub is not managed yet, so | |
196 # publisher is not checked and can be easily spoofed. This need to be fixed | |
197 # quickly. | |
198 microblog_data = self.item2gbdata(item, "comment") | |
199 microblog_data["service"] = service.userhost() | |
200 microblog_data["node"] = node_identifier | |
201 microblog_data["verified_publisher"] = "true" if publisher else "false" | |
202 | |
203 self.host.bridge.personalEvent(publisher.full() if publisher else microblog_data["author"], "MICROBLOG", microblog_data, profile) | |
193 | 204 |
194 def _parseAccessData(self, microblog_data, item): | 205 def _parseAccessData(self, microblog_data, item): |
195 P = self.host.plugins["XEP-0060"] | 206 P = self.host.plugins["XEP-0060"] |
196 form_elts = filter(lambda elt: elt.name == "x", item.children) | 207 form_elts = filter(lambda elt: elt.name == "x", item.children) |
197 for form_elt in form_elts: | 208 for form_elt in form_elts: |
331 return self.host.plugins["XEP-0060"].publish(service, node, items=[mblog_item], profile_key=profile) | 342 return self.host.plugins["XEP-0060"].publish(service, node, items=[mblog_item], profile_key=profile) |
332 | 343 |
333 def _itemsConstruction(self, items, pub_jid, client): | 344 def _itemsConstruction(self, items, pub_jid, client): |
334 """ Transforms items to group blog data and manage comments node | 345 """ Transforms items to group blog data and manage comments node |
335 @param items: iterable of items | 346 @param items: iterable of items |
347 @param pub_jib: jid of the publisher | |
348 @param client: SatXMPPClient instance | |
336 @return: list of group blog data """ | 349 @return: list of group blog data """ |
337 ret = [] | 350 ret = [] |
338 for item in items: | 351 for item in items: |
339 gbdata = self.item2gbdata(item) | 352 gbdata = self.item2gbdata(item) |
340 ret.append(gbdata) | 353 ret.append(gbdata) |
341 # if there is a comments node, we subscribe to it | 354 # if there is a comments node, we subscribe to it |
342 if "comments_node" in gbdata and pub_jid.userhostJID() != client.jid.userhostJID(): | 355 if "comments_node" in gbdata and pub_jid.userhostJID() != client.jid.userhostJID(): |
343 try: | 356 try: |
357 # every comments node must be subscribed | |
344 self.host.plugins["XEP-0060"].subscribe(jid.JID(gbdata["comments_service"]), gbdata["comments_node"], | 358 self.host.plugins["XEP-0060"].subscribe(jid.JID(gbdata["comments_service"]), gbdata["comments_node"], |
345 profile_key=client.profile) | 359 profile_key=client.profile) |
346 self.host.plugins["XEP-0060"].getItems(jid.JID(gbdata["comments_service"]), gbdata["comments_node"], profile_key=client.profile) | 360 # we get all comments of the node, and handle them |
361 defer_getItems = self.host.plugins["XEP-0060"].getItems(jid.JID(gbdata["comments_service"]), gbdata["comments_node"], profile_key=client.profile) | |
362 defer_getItems.addCallback(self._handleCommentsItems, jid.JID(gbdata["comments_service"]), gbdata["comments_node"], client.profile) | |
347 except KeyError: | 363 except KeyError: |
348 warning("Missing key for comments") | 364 warning("Missing key for comments") |
349 return ret | 365 return ret |
350 | 366 |
351 def getLastGroupBlogs(self, pub_jid_s, max_items=10, profile_key='@DEFAULT@'): | 367 def getLastGroupBlogs(self, pub_jid_s, max_items=10, profile_key='@DEFAULT@'): |