From 8215434c65413e507629964dc6723a2344ac16b3 Mon Sep 17 00:00:00 2001 From: floatingghost Date: Mon, 11 Jul 2022 13:48:43 +0000 Subject: [PATCH] also resolve @full@tags in mfm (#62) Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/62 --- .../article_note_page_validator.ex | 18 ++++++++++++++++-- test/fixtures/misskey/mfm_x_format.json | 7 ++++++- .../article_note_page_validator_test.exs | 11 ++++++++++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/web/activity_pub/object_validators/article_note_page_validator.ex b/lib/pleroma/web/activity_pub/object_validators/article_note_page_validator.ex index 243a25b18..5e377c294 100644 --- a/lib/pleroma/web/activity_pub/object_validators/article_note_page_validator.ex +++ b/lib/pleroma/web/activity_pub/object_validators/article_note_page_validator.ex @@ -81,9 +81,23 @@ defp fix_replies(%{"replies" => %{"first" => first}} = data) do defp fix_replies(data), do: data - defp remote_mention_resolver(%{"tag" => tags}, "@" <> nickname = mention, buffer, opts, acc) do + defp remote_mention_resolver( + %{"id" => ap_id, "tag" => tags}, + "@" <> nickname = mention, + buffer, + opts, + acc + ) do + initial_host = + ap_id + |> URI.parse() + |> Map.get(:host) + with mention_tag <- - Enum.find(tags, fn t -> t["type"] == "Mention" && t["name"] == mention end), + Enum.find(tags, fn t -> + t["type"] == "Mention" && + (t["name"] == mention || mention == "#{t["name"]}@#{initial_host}") + end), false <- is_nil(mention_tag), {:ok, %User{} = user} <- User.get_or_fetch_by_ap_id(mention_tag["href"]) do link = Pleroma.Formatter.mention_tag(user, nickname, opts) diff --git a/test/fixtures/misskey/mfm_x_format.json b/test/fixtures/misskey/mfm_x_format.json index a24e90e7e..21aae9204 100644 --- a/test/fixtures/misskey/mfm_x_format.json +++ b/test/fixtures/misskey/mfm_x_format.json @@ -5,7 +5,7 @@ "summary": null, "content": "this gets replaced", "source": { - "content": "@akkoma_user @remote_user @oops_not_a_mention linkifylink #dancedance $[jelly mfm goes here] \n\n## aaa", + "content": "@akkoma_user @remote_user @full_tag_remote_user@misskey.local.live @oops_not_a_mention linkifylink #dancedance $[jelly mfm goes here] \n\n## aaa", "mediaType": "text/x.misskeymarkdown" }, "published": "2022-07-10T15:37:36.368Z", @@ -34,6 +34,11 @@ "type": "Mention", "href": "http://misskey.local.live/users/remote_user", "name": "@remote_user" + }, + { + "type": "Mention", + "href": "http://misskey.local.live/users/full_tag_remote_user", + "name": "@full_tag_remote_user" } ] } diff --git a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs index 4ea7a5bc0..8b3982916 100644 --- a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs @@ -80,6 +80,12 @@ test "a misskey MFM status with a content field should work and be linked", _ do ap_id: "http://misskey.local.live/users/remote_user" }) + full_tag_remote_user = + insert(:user, %{ + nickname: "full_tag_remote_user", + ap_id: "http://misskey.local.live/users/full_tag_remote_user" + }) + insert(:user, %{ap_id: "https://misskey.local.live/users/92hzkskwgy"}) note = @@ -93,7 +99,7 @@ test "a misskey MFM status with a content field should work and be linked", _ do content: content, source: %{ "content" => - "@akkoma_user @remote_user @oops_not_a_mention linkifylink #dancedance $[jelly mfm goes here] \n\n## aaa", + "@akkoma_user @remote_user @full_tag_remote_user@misskey.local.live @oops_not_a_mention linkifylink #dancedance $[jelly mfm goes here] \n\n## aaa", "mediaType" => "text/x.misskeymarkdown" } } @@ -105,6 +111,9 @@ test "a misskey MFM status with a content field should work and be linked", _ do assert content =~ "@remote_user" + assert content =~ + "@full_tag_remote_user" + assert content =~ "@oops_not_a_mention" assert content =~ "$[jelly mfm goes here]

## aaa" end