plugin XEP-0060: node create/delete improvments:

- use client instead of profile for createNode and deleteNode
    - new bridge method psCreateNode
    - renamed psDeleteNode to psNodeDelete
This commit is contained in:
Goffi 2017-04-03 00:22:58 +02:00
commit 697da436af
2 changed files with 24 additions and 10 deletions

View file

@ -86,12 +86,13 @@ class XEP_0060(object):
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 @@ class XEP_0060(object):
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 @@ class XEP_0060(object):
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)
def deleteNode(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE):
client = self.host.getClient(profile_key)
return self.deleteNode(client, jid.JID(service_s) if service_s else None, nodeIdentifier)
def deleteNode(self, client, service, nodeIdentifier):
return client.pubsub_client.deleteNode(service, nodeIdentifier)
def _retractItem(self, service_s, nodeIdentifier, itemIdentifier, notify, profile_key):

View file

@ -512,7 +512,7 @@ class XEP_0277(object):
comments_service = self.getCommentsService(client, service)
try:
yield self._p.createNode(comments_service, comments_node, options, profile_key=profile)
yield self._p.createNode(client, comments_service, comments_node, options)
except error.StanzaError as e:
if e.condition == 'conflict':
log.info(u"node {} already exists on service {}".format(comments_node, comments_service))
@ -629,7 +629,9 @@ class XEP_0277(object):
If the node already exists, it change options
@param access: Node access model, according to xep-0060 #4.5
@param profile_key: profile key"""
@param profile_key: profile key
"""
client = self.host.getClient(profile_key)
_jid, xmlstream = self.host.getJidNStream(profile_key)
if not _jid:
@ -650,14 +652,14 @@ class XEP_0277(object):
#If the node already exists, the condition is "conflict",
#else we have an unmanaged error
if s_error.value.condition == 'conflict':
#d = self.host.plugins["XEP-0060"].deleteNode(_jid.userhostJID(), NS_MICROBLOG, profile_key=profile_key)
#d = self.host.plugins["XEP-0060"].deleteNode(client, _jid.userhostJID(), NS_MICROBLOG)
#d.addCallback(lambda x: create_node().addCallback(cb).addErrback(fatal_err))
change_node_options().addCallback(cb).addErrback(fatal_err)
else:
fatal_err(s_error)
def create_node():
return self._p.createNode(_jid.userhostJID(), NS_MICROBLOG, _options, profile_key=profile_key)
return self._p.createNode(client, _jid.userhostJID(), NS_MICROBLOG, _options)
def change_node_options():
return self._p.setOptions(_jid.userhostJID(), NS_MICROBLOG, _jid.userhostJID(), _options, profile_key=profile_key)