diff --git a/sat/plugins/plugin_comp_ap_gateway/__init__.py b/sat/plugins/plugin_comp_ap_gateway/__init__.py index 45826350..b1721078 100644 --- a/sat/plugins/plugin_comp_ap_gateway/__init__.py +++ b/sat/plugins/plugin_comp_ap_gateway/__init__.py @@ -1778,8 +1778,37 @@ class APGateway: @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 @@ class APGateway: ) 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,