Mercurial > libervia-backend
changeset 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 | 893030a9d351 |
children | 77a3d0a28642 |
files | frontends/src/quick_frontend/quick_blog.py src/plugins/plugin_xep_0060.py src/plugins/plugin_xep_0277.py |
diffstat | 3 files changed, 24 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_blog.py Mon Apr 03 00:13:33 2017 +0200 +++ b/frontends/src/quick_frontend/quick_blog.py Mon Apr 03 00:22:58 2017 +0200 @@ -316,7 +316,7 @@ """ # TODO: manage several comments nodes case. if self.item.comments: - self.blog.host.bridge.psDeleteNode(unicode(self.item.comments_service) or "", self.item.comments_node, profile=self.blog.profile) + self.blog.host.bridge.psNodeDelete(unicode(self.item.comments_service) or "", self.item.comments_node, profile=self.blog.profile) self.blog.host.bridge.mbRetract(unicode(self.service or ""), self.node or "", self.item.id, profile=self.blog.profile)
--- 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):
--- a/src/plugins/plugin_xep_0277.py Mon Apr 03 00:13:33 2017 +0200 +++ b/src/plugins/plugin_xep_0277.py Mon Apr 03 00:22:58 2017 +0200 @@ -512,7 +512,7 @@ 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 @@ 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 @@ #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)