diff 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
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0277.py	Wed Nov 15 08:55:47 2017 +0100
+++ b/src/plugins/plugin_xep_0277.py	Wed Nov 15 08:57:19 2017 +0100
@@ -474,9 +474,23 @@
         """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):