From 75a5716e1772db1667b6264981e752970b010cff Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 22 Apr 2021 18:20:41 +0200 Subject: [PATCH] plugin XEP-0346: bridge method to retrieve template, submitted, or application namespaces --- sat/plugins/plugin_xep_0346.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/sat/plugins/plugin_xep_0346.py b/sat/plugins/plugin_xep_0346.py index e752cd7a..c5e81ae9 100644 --- a/sat/plugins/plugin_xep_0346.py +++ b/sat/plugins/plugin_xep_0346.py @@ -94,6 +94,27 @@ class PubsubSchema(object): method=self._getSchemaDict, async_=True, ) + host.bridge.addMethod( + "psSchemaApplicationNSGet", + ".plugin", + in_sign="s", + out_sign="s", + method=self.getApplicationNS, + ) + host.bridge.addMethod( + "psSchemaTemplateNodeGet", + ".plugin", + in_sign="s", + out_sign="s", + method=self.getTemplateNS, + ) + host.bridge.addMethod( + "psSchemaSubmittedNodeGet", + ".plugin", + in_sign="s", + out_sign="s", + method=self.getSubmittedNS, + ) host.bridge.addMethod( "psItemsFormGet", ".plugin", @@ -122,6 +143,11 @@ class PubsubSchema(object): namespace = namespace[len(TEMPLATE_PREFIX):] return namespace + def getTemplateNS(self, namespace: str) -> str: + """Returns node used for data template (i.e. schema)""" + app_ns = self.getApplicationNS(namespace) + return f"{TEMPLATE_PREFIX}{app_ns}" + def getSubmittedNS(self, namespace: str) -> str: """Returns node to use to submit forms""" return f"{SUBMITTED_PREFIX}{self.getApplicationNS(namespace)}" @@ -244,8 +270,7 @@ class PubsubSchema(object): @param schema(domish.Element, None): schema to set None if schema need to be removed """ - app_ns = self.getApplicationNS(nodeIdentifier) - node_id = f"{TEMPLATE_PREFIX}{app_ns}" + node_id = self.getTemplateNS(nodeIdentifier) node_options = { self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN, self._p.OPT_PERSIST_ITEMS: 1, @@ -480,7 +505,7 @@ class PubsubSchema(object): field.values = values_list - await self._p.sendItem( + return await self._p.sendItem( client, service, nodeIdentifier, form.toElement(), item_id, extra ) @@ -680,7 +705,7 @@ class PubsubSchema(object): - 'updated' is set everytime @param extra(dict, None): same as for [XEP-0060.sendItem] with additional keys: - update(bool): if True, get previous item data to merge with current one - if True, item_id must be None + if True, item_id must be set @param form_ns (unicode, None): namespace of the form needed when an update is done @param default_node(unicode, None): value to use if node is not set