diff sat/plugins/plugin_xep_0346.py @ 3509:b977c74f9c85

plugin XEP-0346: bridge method to retrieve template, submitted, or application namespaces
author Goffi <goffi@goffi.org>
date Thu, 22 Apr 2021 18:20:41 +0200
parents be6d91572633
children edc79cefe968 422049bb81d3
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0346.py	Thu Apr 22 18:19:52 2021 +0200
+++ b/sat/plugins/plugin_xep_0346.py	Thu Apr 22 18:20:41 2021 +0200
@@ -95,6 +95,27 @@
             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",
             in_sign="ssssiassa{ss}s",
@@ -122,6 +143,11 @@
             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 @@
         @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 @@
 
             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 @@
                 - '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