From bf91404351f558db481a75c1b9f0b513f3690e8c Mon Sep 17 00:00:00 2001 From: Goffi Date: Wed, 15 Nov 2017 08:57:19 +0100 Subject: [PATCH] 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. --- src/plugins/plugin_xep_0277.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/plugins/plugin_xep_0277.py b/src/plugins/plugin_xep_0277.py index 62dfe185..9799a9c8 100755 --- a/src/plugins/plugin_xep_0277.py +++ b/src/plugins/plugin_xep_0277.py @@ -474,9 +474,23 @@ class XEP_0277(object): """Get prefered PubSub service to create comment node @param pubsub_service(jid.JID, None): PubSub service of the parent item - @param return(jid.JID, None): PubSub service to use + @param return((D)jid.JID, None): PubSub service to use """ - return client.pubsub_service if client.pubsub_service is not None else parent_service + if parent_service is not None: + if parent_service.user: + # we are on a PEP + if parent_service.host == client.jid.host: + # it's our server, we use already found client.pubsub_service below + pass + else: + # other server, let's try to find a non PEP service there + d = self.host.findServiceEntity(client, "pubsub", "service", parent_service) + d.addCallback(lambda entity: entity or parent_service) + else: + # parent is already on a normal Pubsub service, we re-use it + return defer.succeed(parent_service) + + return defer.succeed(client.pubsub_service if client.pubsub_service is not None else parent_service) @defer.inlineCallbacks def _manageComments(self, client, mb_data, service, node, item_id, access=None):