changeset 3868:37d2c0282304

component AP gateway (pubsub): only emit a `Follow` activity for microblog subscription: this avoid to emit Follow subscription when an entity wants to subscribe to attachments or other special nodes. rel 370
author Goffi <goffi@goffi.org>
date Thu, 21 Jul 2022 18:05:20 +0200
parents c3e6c54660da
children c0bcbcf5b4b7
files sat/plugins/plugin_comp_ap_gateway/pubsub_service.py
diffstat 1 files changed, 12 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_comp_ap_gateway/pubsub_service.py	Thu Jul 21 18:02:33 2022 +0200
+++ b/sat/plugins/plugin_comp_ap_gateway/pubsub_service.py	Thu Jul 21 18:05:20 2022 +0200
@@ -478,17 +478,19 @@
                     f"unmanaged subscription state: {subscription.state}"
                 )
 
-        req_actor_id, recip_actor_id, inbox = await self.getAPActorIdsAndInbox(
-            requestor, service
-        )
-
-        data = self.apg.createActivity("Follow", req_actor_id, recip_actor_id)
+        if nodeIdentifier == self.apg._m.namespace:
+            # if we subscribe to microblog node, we follow the corresponding account
+            req_actor_id, recip_actor_id, inbox = await self.getAPActorIdsAndInbox(
+                requestor, service
+            )
 
-        resp = await self.apg.signAndPost(inbox, req_actor_id, data)
-        if resp.code >= 300:
-            text = await resp.text()
-            raise error.StanzaError("service-unavailable", text=text)
-        return pubsub.Subscription(nodeIdentifier, requestor, "subscribed")
+            data = self.apg.createActivity("Follow", req_actor_id, recip_actor_id)
+
+            resp = await self.apg.signAndPost(inbox, req_actor_id, data)
+            if resp.code >= 300:
+                text = await resp.text()
+                raise error.StanzaError("service-unavailable", text=text)
+            return pubsub.Subscription(nodeIdentifier, requestor, "subscribed")
 
     @ensure_deferred
     async def unsubscribe(self, requestor, service, nodeIdentifier, subscriber):