changeset 3856:bc7f9d0a404f

component AP gateway: when a repeated blog post is retracted, it converted to suitable Activity: when a retract item is received, the former item is now retrieve from cache, and if it was a "repeat" blog post, it is converted to the suitable `Undo` of `Announce` activity (instead of the default `Delete` activity). rel 370
author Goffi <goffi@goffi.org>
date Thu, 14 Jul 2022 12:55:30 +0200
parents 54305ebf5b94
children 7d11e42b150e
files sat/plugins/plugin_comp_ap_gateway/__init__.py
diffstat 1 files changed, 30 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_comp_ap_gateway/__init__.py	Thu Jul 14 12:55:30 2022 +0200
+++ b/sat/plugins/plugin_comp_ap_gateway/__init__.py	Thu Jul 14 12:55:30 2022 +0200
@@ -1778,8 +1778,37 @@
         @param public: if True, the activity will be addressed to public namespace
         @return: actor_id of the entity deleting the item, activity to send
         """
+        if node is None:
+            node = self._m.namespace
+
         author_account = await self.getAPAccountFromJidAndNode(jid_, node)
         author_actor_id = self.buildAPURL(TYPE_ACTOR, author_account)
+
+        items = await self.host.memory.storage.searchPubsubItems({
+            "profiles": [self.client.profile],
+            "services": [jid_],
+            "names": [item_id]
+        })
+        if not items:
+            log.warning(
+                f"Deleting an unknown item at service {jid_}, node {node} and id "
+                f"{item_id}"
+            )
+        else:
+            try:
+                mb_data = await self._m.item2mbdata(self.client, items[0].data, jid_, node)
+                if "repeated" in mb_data["extra"]:
+                    # we are deleting a repeated item, we must translate this to an
+                    # "Undo" of the "Announce" activity instead of a "Delete" one
+                    announce = await self.repeatedMB2APItem(mb_data)
+                    undo = self.createActivity("Undo", author_actor_id, announce)
+                    return author_actor_id, undo
+            except Exception as e:
+                log.debug(
+                    f"Can't parse item, maybe it's not a blog item: {e}\n"
+                    f"{items[0].toXml()}"
+                )
+
         url_item = self.buildAPURL(TYPE_ITEM, author_account, item_id)
         ap_item = self.createActivity(
             "Delete",
@@ -1791,8 +1820,7 @@
         )
         if public:
             ap_item["to"] = [NS_AP_PUBLIC]
-        url_actor = author_actor_id
-        return url_actor, ap_item
+        return author_actor_id, ap_item
 
     def _messageReceivedTrigger(
         self,