diff sat/plugins/plugin_misc_lists.py @ 3463:483bcfeb11c9

plugin misc list: register lists for pubsub invitations
author Goffi <goffi@goffi.org>
date Fri, 19 Feb 2021 15:52:28 +0100
parents 02a8d227d5bb
children 54b9cdbeb335
line wrap: on
line diff
--- a/sat/plugins/plugin_misc_lists.py	Fri Feb 19 15:50:22 2021 +0100
+++ b/sat/plugins/plugin_misc_lists.py	Fri Feb 19 15:52:28 2021 +0100
@@ -16,12 +16,13 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import shortuuid
-from typing import Tuple
+from typing import List, Tuple, Optional
 from twisted.internet import defer
 from twisted.words.xish import domish
 from twisted.words.protocols.jabber import jid
 from wokkel import data_form
 from sat.core.i18n import _, D_
+from sat.core.xmpp import SatXMPPEntity
 from sat.core.constants import Const as C
 from sat.tools.common import uri
 from sat.tools.common import data_format
@@ -39,7 +40,8 @@
     C.PI_IMPORT_NAME: "LISTS",
     C.PI_TYPE: "EXP",
     C.PI_PROTOCOLS: [],
-    C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0346", "XEP-0277", "IDENTITY"],
+    C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0346", "XEP-0277", "IDENTITY",
+                        "PUBSUB_INVITATION"],
     C.PI_MAIN: "PubsubLists",
     C.PI_HANDLER: "no",
     C.PI_DESCRIPTION: _("""Pubsub lists management plugin"""),
@@ -208,6 +210,9 @@
         self._s = self.host.plugins["XEP-0346"]
         self.namespace = self._s.getSubmittedNS(APP_NS_TICKETS)
         host.registerNamespace("tickets", APP_NS_TICKETS)
+        self.host.plugins["PUBSUB_INVITATION"].register(
+            APP_NS_TICKETS, self
+        )
         self._p = self.host.plugins["XEP-0060"]
         self._m = self.host.plugins["XEP-0277"]
         host.bridge.addMethod(
@@ -275,6 +280,30 @@
             async_=True,
         )
 
+    async def onInvitationPreflight(
+        self,
+        client: SatXMPPEntity,
+        namespace: str,
+        name: str,
+        extra: dict,
+        service: jid.JID,
+        node: str,
+        item_id: Optional[str],
+        item_elt: domish.Element
+    ) -> None:
+        try:
+            schema = await self._s.getSchemaForm(client, service, node)
+        except Exception as e:
+            log.warning(f"Can't retrive node schema as {node!r} [{service}]: {e}")
+        else:
+            try:
+                field_type = schema[NS_TICKETS_TYPE]
+            except KeyError:
+                log.debug("no type found in list schema")
+            else:
+                list_elt = extra["element"] = domish.Element((APP_NS_TICKETS, "list"))
+                list_elt["type"] = field_type
+
     def _set(self, service, node, values, schema=None, item_id=None, extra='',
              profile_key=C.PROF_KEY_NONE):
         client, service, node, schema, item_id, extra = self._s.prepareBridgeSet(