comparison src/plugins/plugin_xep_0277.py @ 2433:014feb75092d

plugin XEP-0277: better getCommentsService: getCommentsService now checks if the parent service is on a third party server and if it's PEP, and return the service to use accordingly.
author Goffi <goffi@goffi.org>
date Wed, 15 Nov 2017 08:57:19 +0100
parents 59100136f07a
children 91bbad17fd53
comparison
equal deleted inserted replaced
2432:c6d859df4b27 2433:014feb75092d
472 472
473 def getCommentsService(self, client, parent_service=None): 473 def getCommentsService(self, client, parent_service=None):
474 """Get prefered PubSub service to create comment node 474 """Get prefered PubSub service to create comment node
475 475
476 @param pubsub_service(jid.JID, None): PubSub service of the parent item 476 @param pubsub_service(jid.JID, None): PubSub service of the parent item
477 @param return(jid.JID, None): PubSub service to use 477 @param return((D)jid.JID, None): PubSub service to use
478 """ 478 """
479 return client.pubsub_service if client.pubsub_service is not None else parent_service 479 if parent_service is not None:
480 if parent_service.user:
481 # we are on a PEP
482 if parent_service.host == client.jid.host:
483 # it's our server, we use already found client.pubsub_service below
484 pass
485 else:
486 # other server, let's try to find a non PEP service there
487 d = self.host.findServiceEntity(client, "pubsub", "service", parent_service)
488 d.addCallback(lambda entity: entity or parent_service)
489 else:
490 # parent is already on a normal Pubsub service, we re-use it
491 return defer.succeed(parent_service)
492
493 return defer.succeed(client.pubsub_service if client.pubsub_service is not None else parent_service)
480 494
481 @defer.inlineCallbacks 495 @defer.inlineCallbacks
482 def _manageComments(self, client, mb_data, service, node, item_id, access=None): 496 def _manageComments(self, client, mb_data, service, node, item_id, access=None):
483 """Check comments keys in mb_data and create comments node if necessary 497 """Check comments keys in mb_data and create comments node if necessary
484 498