diff sat/plugins/plugin_xep_0060.py @ 3589:ed037c98df37

plugin XEP-0060: add trigger points
author Goffi <goffi@goffi.org>
date Thu, 29 Jul 2021 17:26:59 +0200
parents 2c7a52a62be3
children 1269c2d788be
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0060.py	Thu Jul 29 17:10:36 2021 +0200
+++ b/sat/plugins/plugin_xep_0060.py	Thu Jul 29 17:26:59 2021 +0200
@@ -586,12 +586,25 @@
         except AttributeError:
             return []
 
-    async def publish(self, client, service, nodeIdentifier, items=None, options=None):
-        return await client.pubsub_client.publish(
+    async def publish(
+        self,
+        client: SatXMPPEntity,
+        service: jid.JID,
+        nodeIdentifier: str,
+        items: Optional[List[domish.Element]] = None,
+        options: Optional[dict] = None
+    ) -> List[str]:
+        published_ids = await client.pubsub_client.publish(
             service, nodeIdentifier, items, client.pubsub_client.parent.jid,
             options=options
         )
 
+        await self.host.trigger.asyncPoint(
+            "XEP-0060_publish", client, service, nodeIdentifier, items, options,
+            published_ids
+        )
+        return published_ids
+
     def _unwrapMAMMessage(self, message_elt):
         try:
             item_elt = reduce(
@@ -670,6 +683,12 @@
             raise ValueError("items_id can't be used with rsm")
         if extra is None:
             extra = {}
+        cont, ret = await self.host.trigger.asyncReturnPoint(
+            "XEP-0060_getItems", client, service, node, max_items, item_ids, sub_id,
+            rsm_request, extra
+        )
+        if not cont:
+            return ret
         try:
             mam_query = extra["mam"]
         except KeyError:
@@ -1097,11 +1116,23 @@
         d.addCallback(lambda subscription: subscription.subscriptionIdentifier or "")
         return d
 
-    async def subscribe(self, client, service, nodeIdentifier, sub_jid=None, options=None):
+    async def subscribe(
+        self,
+        client: SatXMPPEntity,
+        service: jid.JID,
+        nodeIdentifier: str,
+        sub_jid: Optional[jid.JID] = None,
+        options: Optional[dict] = None
+    ) -> pubsub.Subscription:
         # TODO: reimplement a subscribtion cache, checking that we have not subscription before trying to subscribe
-        return await client.pubsub_client.subscribe(
+        subscription = await client.pubsub_client.subscribe(
             service, nodeIdentifier, sub_jid or client.jid.userhostJID(), options=options
         )
+        await self.host.trigger.asyncPoint(
+            "XEP-0060_subscribe", client, service, nodeIdentifier, sub_jid, options,
+            subscription
+        )
+        return subscription
 
     def _unsubscribe(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE):
         client = self.host.getClient(profile_key)
@@ -1110,20 +1141,24 @@
 
     async def unsubscribe(
         self,
-        client,
-        service,
-        nodeIdentifier,
+        client: SatXMPPEntity,
+        service: jid.JID,
+        nodeIdentifier: str,
         sub_jid=None,
         subscriptionIdentifier=None,
         sender=None,
     ):
-        return await client.pubsub_client.unsubscribe(
+        await client.pubsub_client.unsubscribe(
             service,
             nodeIdentifier,
             sub_jid or client.jid.userhostJID(),
             subscriptionIdentifier,
             sender,
         )
+        await self.host.trigger.asyncPoint(
+            "XEP-0060_unsubscribe", client, service, nodeIdentifier, sub_jid,
+            subscriptionIdentifier, sender
+        )
 
     def _subscriptions(self, service, nodeIdentifier="", profile_key=C.PROF_KEY_NONE):
         client = self.host.getClient(profile_key)