diff src/plugins/plugin_xep_0060.py @ 2218:6a2fa651d7fa

plugin XEP-0060: node create/delete improvments: - use client instead of profile for createNode and deleteNode - new bridge method psCreateNode - renamed psDeleteNode to psNodeDelete
author Goffi <goffi@goffi.org>
date Mon, 03 Apr 2017 00:22:58 +0200
parents 59d3de85a0cb
children 6856b7225c5b
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0060.py	Mon Apr 03 00:13:33 2017 +0200
+++ b/src/plugins/plugin_xep_0060.py	Mon Apr 03 00:22:58 2017 +0200
@@ -86,12 +86,13 @@
         self._mam = host.plugins.get('XEP-0313')
         self._node_cb = {} # dictionnary of callbacks for node (key: node, value: list of callbacks)
         self.rt_sessions = sat_defer.RTDeferredSessions()
+        host.bridge.addMethod("psNodeCreate", ".plugin", in_sign='ssa{ss}s', out_sign='s', method=self._createNode, async=True)
         host.bridge.addMethod("psNodeConfigurationGet", ".plugin", in_sign='sss', out_sign='a{ss}', method=self._getNodeConfiguration, async=True)
         host.bridge.addMethod("psNodeConfigurationSet", ".plugin", in_sign='ssa{ss}s', out_sign='', method=self._setNodeConfiguration, async=True)
         host.bridge.addMethod("psAffiliationsGet", ".plugin", in_sign='sss', out_sign='a{ss}', method=self._getAffiliations, async=True)
         host.bridge.addMethod("psNodeAffiliationsGet", ".plugin", in_sign='sss', out_sign='a{ss}', method=self._getNodeAffiliations, async=True)
         host.bridge.addMethod("psNodeAffiliationsSet", ".plugin", in_sign='ssa{ss}s', out_sign='', method=self._setNodeAffiliations, async=True)
-        host.bridge.addMethod("psDeleteNode", ".plugin", in_sign='sss', out_sign='', method=self._deleteNode, async=True)
+        host.bridge.addMethod("psNodeDelete", ".plugin", in_sign='sss', out_sign='', method=self._deleteNode, async=True)
         host.bridge.addMethod("psItemGet", ".plugin", in_sign='ssiassa{ss}s', out_sign='(asa{ss})', method=self._getItems, async=True)
         host.bridge.addMethod("psRetractItem", ".plugin", in_sign='sssbs', out_sign='', method=self._retractItem, async=True)
         host.bridge.addMethod("psRetractItems", ".plugin", in_sign='ssasbs', out_sign='', method=self._retractItems, async=True)
@@ -393,8 +394,19 @@
         client = self.host.getClient(profile_key)
         return client.pubsub_client.setOptions(service, nodeIdentifier, subscriber, options, subscriptionIdentifier)
 
-    def createNode(self, service, nodeIdentifier, options, profile_key=C.PROF_KEY_NONE):
+    def _createNode(self, service_s, nodeIdentifier, options, profile_key):
         client = self.host.getClient(profile_key)
+        return self.createNode(client, jid.JID(service_s) if service_s else None, nodeIdentifier, options)
+
+    def createNode(self, client, service, nodeIdentifier=None, options=None):
+        """Create a new node
+
+        @param service(jid.JID): PubSub service,
+        @param NodeIdentifier(unicode, None): node name
+           use None to create instant node (identifier will be returned by this method)
+        @param option(dict[unicode, unicode], None): node configuration options
+        @return (unicode): identifier of the created node (may be different from requested name)
+        """
         return client.pubsub_client.createNode(service, nodeIdentifier, options)
 
     def _getNodeConfiguration(self, service_s, nodeIdentifier, profile_key):
@@ -513,10 +525,10 @@
         return d
 
     def _deleteNode(self, service_s, nodeIdentifier, profile_key):
-        return self.deleteNode(jid.JID(service_s) if service_s else None, nodeIdentifier, profile_key)
+        client = self.host.getClient(profile_key)
+        return self.deleteNode(client, jid.JID(service_s) if service_s else None, nodeIdentifier)
 
-    def deleteNode(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE):
-        client = self.host.getClient(profile_key)
+    def deleteNode(self, client, service, nodeIdentifier):
         return client.pubsub_client.deleteNode(service, nodeIdentifier)
 
     def _retractItem(self, service_s, nodeIdentifier, itemIdentifier, notify, profile_key):