also resolve @full@tags in mfm (#62)
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/62
This commit is contained in:
parent
ff6c8455fb
commit
8215434c65
3 changed files with 32 additions and 4 deletions
|
@ -81,9 +81,23 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator do
|
||||||
|
|
||||||
defp fix_replies(data), do: data
|
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 <-
|
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),
|
false <- is_nil(mention_tag),
|
||||||
{:ok, %User{} = user} <- User.get_or_fetch_by_ap_id(mention_tag["href"]) do
|
{:ok, %User{} = user} <- User.get_or_fetch_by_ap_id(mention_tag["href"]) do
|
||||||
link = Pleroma.Formatter.mention_tag(user, nickname, opts)
|
link = Pleroma.Formatter.mention_tag(user, nickname, opts)
|
||||||
|
|
7
test/fixtures/misskey/mfm_x_format.json
vendored
7
test/fixtures/misskey/mfm_x_format.json
vendored
|
@ -5,7 +5,7 @@
|
||||||
"summary": null,
|
"summary": null,
|
||||||
"content": "this gets replaced",
|
"content": "this gets replaced",
|
||||||
"source": {
|
"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"
|
"mediaType": "text/x.misskeymarkdown"
|
||||||
},
|
},
|
||||||
"published": "2022-07-10T15:37:36.368Z",
|
"published": "2022-07-10T15:37:36.368Z",
|
||||||
|
@ -34,6 +34,11 @@
|
||||||
"type": "Mention",
|
"type": "Mention",
|
||||||
"href": "http://misskey.local.live/users/remote_user",
|
"href": "http://misskey.local.live/users/remote_user",
|
||||||
"name": "@remote_user"
|
"name": "@remote_user"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Mention",
|
||||||
|
"href": "http://misskey.local.live/users/full_tag_remote_user",
|
||||||
|
"name": "@full_tag_remote_user"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,12 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest
|
||||||
ap_id: "http://misskey.local.live/users/remote_user"
|
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"})
|
insert(:user, %{ap_id: "https://misskey.local.live/users/92hzkskwgy"})
|
||||||
|
|
||||||
note =
|
note =
|
||||||
|
@ -93,7 +99,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest
|
||||||
content: content,
|
content: content,
|
||||||
source: %{
|
source: %{
|
||||||
"content" =>
|
"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"
|
"mediaType" => "text/x.misskeymarkdown"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,6 +111,9 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest
|
||||||
assert content =~
|
assert content =~
|
||||||
"<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{remote_user.id}\" href=\"#{remote_user.ap_id}\" rel=\"ugc\">@<span>remote_user</span></a></span>"
|
"<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{remote_user.id}\" href=\"#{remote_user.ap_id}\" rel=\"ugc\">@<span>remote_user</span></a></span>"
|
||||||
|
|
||||||
|
assert content =~
|
||||||
|
"<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{full_tag_remote_user.id}\" href=\"#{full_tag_remote_user.ap_id}\" rel=\"ugc\">@<span>full_tag_remote_user</span></a></span>"
|
||||||
|
|
||||||
assert content =~ "@oops_not_a_mention"
|
assert content =~ "@oops_not_a_mention"
|
||||||
assert content =~ "$[jelly mfm goes here] <br><br>## aaa"
|
assert content =~ "$[jelly mfm goes here] <br><br>## aaa"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue