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
This commit is contained in:
Goffi 2022-07-14 12:55:30 +02:00
commit 51f786bc21

View file

@ -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,