changeset 4017:4a2c261646b6

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).
author Goffi <goffi@goffi.org>
date Mon, 20 Mar 2023 11:47:13 +0100
parents 97df34151c6d
children 86efd854dee1
files sat/plugins/plugin_comp_ap_gateway/__init__.py
diffstat 1 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_comp_ap_gateway/__init__.py	Sat Mar 18 23:11:28 2023 +0100
+++ b/sat/plugins/plugin_comp_ap_gateway/__init__.py	Mon Mar 20 11:47:13 2023 +0100
@@ -2225,7 +2225,16 @@
             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