diff src/plugins/plugin_xep_0060.py @ 2196:d3e48c9a255e

plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
author Goffi <goffi@goffi.org>
date Mon, 13 Mar 2017 23:18:00 +0100
parents d65275ac39b3
children 44f12990e275
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0060.py	Mon Mar 13 23:17:13 2017 +0100
+++ b/src/plugins/plugin_xep_0060.py	Mon Mar 13 23:18:00 2017 +0100
@@ -85,6 +85,7 @@
         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("psNodeConfigurationGet", ".plugin", in_sign='sss', out_sign='a{ss}', method=self._getNodeConfiguration, async=True)
         host.bridge.addMethod("psDeleteNode", ".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)
@@ -391,6 +392,30 @@
         client = self.host.getClient(profile_key)
         return client.pubsub_client.createNode(service, nodeIdentifier, options)
 
+    def _getNodeConfiguration(self, service_s, nodeIdentifier, profile_key):
+        client = self.host.getClient(profile_key)
+        d = self.getConfiguration(client, jid.JID(service_s) if service_s else None, nodeIdentifier)
+        def serialize(form):
+            # FIXME: better more generic dataform serialisation should be available in SàT
+            return {f.var: unicode(f.value) for f in form.fields.values()}
+        d.addCallback(serialize)
+        return d
+
+    def getConfiguration(self, client, service, nodeIdentifier):
+        request = pubsub.PubSubRequest('configureGet')
+        request.recipient = service
+        request.nodeIdentifier = nodeIdentifier
+
+        def cb(iq):
+            form = data_form.findForm(iq.pubsub.configure,
+                                      pubsub.NS_PUBSUB_NODE_CONFIG)
+            form.typeCheck()
+            return form
+
+        d = request.send(client.xmlstream)
+        d.addCallback(cb)
+        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)