plugin XEP-0346: bridge method to retrieve template, submitted, or application namespaces

This commit is contained in:
Goffi 2021-04-22 18:20:41 +02:00
commit 75a5716e17

View file

@ -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