diff src/plugins/plugin_xep_0060.py @ 2206:59d3de85a0cb

plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
author Goffi <goffi@goffi.org>
date Sun, 26 Mar 2017 18:06:58 +0200
parents 427391c706eb
children 6a2fa651d7fa
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0060.py	Sun Mar 26 16:57:53 2017 +0200
+++ b/src/plugins/plugin_xep_0060.py	Sun Mar 26 18:06:58 2017 +0200
@@ -90,6 +90,7 @@
         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("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)
@@ -492,6 +493,25 @@
         d.addCallback(cb)
         return d
 
+    def _setNodeAffiliations(self, service_s, nodeIdentifier, affiliations, profile_key=C.PROF_KEY_NONE):
+        client = self.host.getClient(profile_key)
+        affiliations = {jid.JID(jid_): affiliation for jid_, affiliation in affiliations.iteritems()}
+        d = self.setNodeAffiliations(client, jid.JID(service_s) if service_s else None, nodeIdentifier, affiliations)
+        return d
+
+    def setNodeAffiliations(self, client, service, nodeIdentifier, affiliations):
+        """Update affiliations of a node owned by profile
+
+        @param affiliations(dict[jid.JID, unicode]): affiliations to set
+            check https://xmpp.org/extensions/xep-0060.html#affiliations for a list of possible affiliations
+        """
+        request = pubsub.PubSubRequest('affiliationsSet')
+        request.recipient = service
+        request.nodeIdentifier = nodeIdentifier
+        request.affiliations = affiliations
+        d = request.send(client.xmlstream)
+        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)