component AP gateway: add mention to direct messages:

when a direct (not public) message is sent to AP peer, a mention should be present
otherwise the peer won't receive a notification in most AP implementation (notably
Mastodon).
This commit is contained in:
Goffi 2023-03-20 11:47:13 +01:00
commit 182fef1134

View file

@ -2225,7 +2225,16 @@ class APGateway:
mb_data["id"] = origin_id
client = self.client.getVirtualClient(mess_data["from"])
ap_item = await self.mb_data_2_ap_item(client, mb_data, public=False)
ap_item["object"]["to"] = ap_item["to"] = [actor_id]
ap_object = ap_item["object"]
ap_object["to"] = ap_item["to"] = [actor_id]
# we add a mention to direct message, otherwise peer is not notified in some AP
# implementations (notably Mastodon), and the message may be missed easily.
ap_object.setdefault("tag", []).append({
"type": TYPE_MENTION,
"href": actor_id,
"name": f"@{actor_account}",
})
await self.signAndPost(inbox, ap_item["actor"], ap_item)
return mess_data