comparison 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
comparison
equal deleted inserted replaced
2217:893030a9d351 2218:6a2fa651d7fa
84 log.info(_(u"PubSub plugin initialization")) 84 log.info(_(u"PubSub plugin initialization"))
85 self.host = host 85 self.host = host
86 self._mam = host.plugins.get('XEP-0313') 86 self._mam = host.plugins.get('XEP-0313')
87 self._node_cb = {} # dictionnary of callbacks for node (key: node, value: list of callbacks) 87 self._node_cb = {} # dictionnary of callbacks for node (key: node, value: list of callbacks)
88 self.rt_sessions = sat_defer.RTDeferredSessions() 88 self.rt_sessions = sat_defer.RTDeferredSessions()
89 host.bridge.addMethod("psNodeCreate", ".plugin", in_sign='ssa{ss}s', out_sign='s', method=self._createNode, async=True)
89 host.bridge.addMethod("psNodeConfigurationGet", ".plugin", in_sign='sss', out_sign='a{ss}', method=self._getNodeConfiguration, async=True) 90 host.bridge.addMethod("psNodeConfigurationGet", ".plugin", in_sign='sss', out_sign='a{ss}', method=self._getNodeConfiguration, async=True)
90 host.bridge.addMethod("psNodeConfigurationSet", ".plugin", in_sign='ssa{ss}s', out_sign='', method=self._setNodeConfiguration, async=True) 91 host.bridge.addMethod("psNodeConfigurationSet", ".plugin", in_sign='ssa{ss}s', out_sign='', method=self._setNodeConfiguration, async=True)
91 host.bridge.addMethod("psAffiliationsGet", ".plugin", in_sign='sss', out_sign='a{ss}', method=self._getAffiliations, async=True) 92 host.bridge.addMethod("psAffiliationsGet", ".plugin", in_sign='sss', out_sign='a{ss}', method=self._getAffiliations, async=True)
92 host.bridge.addMethod("psNodeAffiliationsGet", ".plugin", in_sign='sss', out_sign='a{ss}', method=self._getNodeAffiliations, async=True) 93 host.bridge.addMethod("psNodeAffiliationsGet", ".plugin", in_sign='sss', out_sign='a{ss}', method=self._getNodeAffiliations, async=True)
93 host.bridge.addMethod("psNodeAffiliationsSet", ".plugin", in_sign='ssa{ss}s', out_sign='', method=self._setNodeAffiliations, async=True) 94 host.bridge.addMethod("psNodeAffiliationsSet", ".plugin", in_sign='ssa{ss}s', out_sign='', method=self._setNodeAffiliations, async=True)
94 host.bridge.addMethod("psDeleteNode", ".plugin", in_sign='sss', out_sign='', method=self._deleteNode, async=True) 95 host.bridge.addMethod("psNodeDelete", ".plugin", in_sign='sss', out_sign='', method=self._deleteNode, async=True)
95 host.bridge.addMethod("psItemGet", ".plugin", in_sign='ssiassa{ss}s', out_sign='(asa{ss})', method=self._getItems, async=True) 96 host.bridge.addMethod("psItemGet", ".plugin", in_sign='ssiassa{ss}s', out_sign='(asa{ss})', method=self._getItems, async=True)
96 host.bridge.addMethod("psRetractItem", ".plugin", in_sign='sssbs', out_sign='', method=self._retractItem, async=True) 97 host.bridge.addMethod("psRetractItem", ".plugin", in_sign='sssbs', out_sign='', method=self._retractItem, async=True)
97 host.bridge.addMethod("psRetractItems", ".plugin", in_sign='ssasbs', out_sign='', method=self._retractItems, async=True) 98 host.bridge.addMethod("psRetractItems", ".plugin", in_sign='ssasbs', out_sign='', method=self._retractItems, async=True)
98 host.bridge.addMethod("psSubscribeToMany", ".plugin", in_sign='a(ss)sa{ss}s', out_sign='s', method=self._subscribeToMany) 99 host.bridge.addMethod("psSubscribeToMany", ".plugin", in_sign='a(ss)sa{ss}s', out_sign='s', method=self._subscribeToMany)
99 host.bridge.addMethod("psGetSubscribeRTResult", ".plugin", in_sign='ss', out_sign='(ua(sss))', method=self._manySubscribeRTResult, async=True) 100 host.bridge.addMethod("psGetSubscribeRTResult", ".plugin", in_sign='ss', out_sign='(ua(sss))', method=self._manySubscribeRTResult, async=True)
391 392
392 def setOptions(self, service, nodeIdentifier, subscriber, options, subscriptionIdentifier=None, profile_key=C.PROF_KEY_NONE): 393 def setOptions(self, service, nodeIdentifier, subscriber, options, subscriptionIdentifier=None, profile_key=C.PROF_KEY_NONE):
393 client = self.host.getClient(profile_key) 394 client = self.host.getClient(profile_key)
394 return client.pubsub_client.setOptions(service, nodeIdentifier, subscriber, options, subscriptionIdentifier) 395 return client.pubsub_client.setOptions(service, nodeIdentifier, subscriber, options, subscriptionIdentifier)
395 396
396 def createNode(self, service, nodeIdentifier, options, profile_key=C.PROF_KEY_NONE): 397 def _createNode(self, service_s, nodeIdentifier, options, profile_key):
397 client = self.host.getClient(profile_key) 398 client = self.host.getClient(profile_key)
399 return self.createNode(client, jid.JID(service_s) if service_s else None, nodeIdentifier, options)
400
401 def createNode(self, client, service, nodeIdentifier=None, options=None):
402 """Create a new node
403
404 @param service(jid.JID): PubSub service,
405 @param NodeIdentifier(unicode, None): node name
406 use None to create instant node (identifier will be returned by this method)
407 @param option(dict[unicode, unicode], None): node configuration options
408 @return (unicode): identifier of the created node (may be different from requested name)
409 """
398 return client.pubsub_client.createNode(service, nodeIdentifier, options) 410 return client.pubsub_client.createNode(service, nodeIdentifier, options)
399 411
400 def _getNodeConfiguration(self, service_s, nodeIdentifier, profile_key): 412 def _getNodeConfiguration(self, service_s, nodeIdentifier, profile_key):
401 client = self.host.getClient(profile_key) 413 client = self.host.getClient(profile_key)
402 d = self.getConfiguration(client, jid.JID(service_s) if service_s else None, nodeIdentifier) 414 d = self.getConfiguration(client, jid.JID(service_s) if service_s else None, nodeIdentifier)
511 request.affiliations = affiliations 523 request.affiliations = affiliations
512 d = request.send(client.xmlstream) 524 d = request.send(client.xmlstream)
513 return d 525 return d
514 526
515 def _deleteNode(self, service_s, nodeIdentifier, profile_key): 527 def _deleteNode(self, service_s, nodeIdentifier, profile_key):
516 return self.deleteNode(jid.JID(service_s) if service_s else None, nodeIdentifier, profile_key) 528 client = self.host.getClient(profile_key)
517 529 return self.deleteNode(client, jid.JID(service_s) if service_s else None, nodeIdentifier)
518 def deleteNode(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE): 530
519 client = self.host.getClient(profile_key) 531 def deleteNode(self, client, service, nodeIdentifier):
520 return client.pubsub_client.deleteNode(service, nodeIdentifier) 532 return client.pubsub_client.deleteNode(service, nodeIdentifier)
521 533
522 def _retractItem(self, service_s, nodeIdentifier, itemIdentifier, notify, profile_key): 534 def _retractItem(self, service_s, nodeIdentifier, itemIdentifier, notify, profile_key):
523 return self._retractItems(service_s, nodeIdentifier, (itemIdentifier,), notify, profile_key) 535 return self._retractItems(service_s, nodeIdentifier, (itemIdentifier,), notify, profile_key)
524 536