mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 00:26:30 +00:00
Merge branch 'mention-mrf-md' into 'develop'
ForceMentionsInContent: improve display of Markdown posts See merge request pleroma/pleroma!3625
This commit is contained in:
commit
64944c164f
2 changed files with 44 additions and 4 deletions
|
@ -103,10 +103,23 @@ defmodule Pleroma.Web.ActivityPub.MRF.ForceMentionsInContent do
|
|||
end
|
||||
end)
|
||||
|
||||
content =
|
||||
recipients_inline =
|
||||
if added_mentions != "",
|
||||
do: "<span class=\"recipients-inline\">#{added_mentions}</span>" <> content,
|
||||
else: content
|
||||
do: "<span class=\"recipients-inline\">#{added_mentions}</span>",
|
||||
else: ""
|
||||
|
||||
content =
|
||||
cond do
|
||||
# For Markdown posts, insert the mentions inside the first <p> tag
|
||||
recipients_inline != "" && String.starts_with?(content, "<p>") ->
|
||||
"<p>" <> recipients_inline <> String.trim_leading(content, "<p>")
|
||||
|
||||
recipients_inline != "" ->
|
||||
recipients_inline <> content
|
||||
|
||||
true ->
|
||||
content
|
||||
end
|
||||
|
||||
{:ok, put_in(object["object"]["content"], content)}
|
||||
end
|
||||
|
|
|
@ -49,7 +49,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ForceMentionsInContentTest do
|
|||
{:ok, %{"object" => %{"content" => filtered}}} = ForceMentionsInContent.filter(activity)
|
||||
|
||||
assert filtered ==
|
||||
"<span class=\"recipients-inline\"><span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{dielan.id}\" href=\"https://shitposter.club/users/dielan\" rel=\"ugc\">@<span>dielan</span></a></span> <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{coolboymew.id}\" href=\"https://shitposter.club/users/coolboymew\" rel=\"ugc\">@<span>coolboymew</span></a></span> <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{fence.id}\" href=\"https://xyzzy.link/users/fence\" rel=\"ugc\">@<span>fence</span></a></span> <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{hakui.id}\" href=\"https://tuusin.misono-ya.info/users/hakui\" rel=\"ugc\">@<span>hakui</span></a></span> <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{lain.id}\" href=\"https://lain.com/users/lain\" rel=\"ugc\">@<span>lain</span></a></span> </span><p>Haha yeah, you can control who you reply to.</p>"
|
||||
"<p><span class=\"recipients-inline\"><span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{dielan.id}\" href=\"https://shitposter.club/users/dielan\" rel=\"ugc\">@<span>dielan</span></a></span> <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{coolboymew.id}\" href=\"https://shitposter.club/users/coolboymew\" rel=\"ugc\">@<span>coolboymew</span></a></span> <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{fence.id}\" href=\"https://xyzzy.link/users/fence\" rel=\"ugc\">@<span>fence</span></a></span> <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{hakui.id}\" href=\"https://tuusin.misono-ya.info/users/hakui\" rel=\"ugc\">@<span>hakui</span></a></span> <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{lain.id}\" href=\"https://lain.com/users/lain\" rel=\"ugc\">@<span>lain</span></a></span> </span>Haha yeah, you can control who you reply to.</p>"
|
||||
end
|
||||
|
||||
test "the replied-to user is sorted to the left" do
|
||||
|
@ -134,4 +134,31 @@ defmodule Pleroma.Web.ActivityPub.MRF.ForceMentionsInContentTest do
|
|||
{:ok, %{"object" => %{"content" => filtered}}} = ForceMentionsInContent.filter(activity)
|
||||
assert filtered == "Mama mia!"
|
||||
end
|
||||
|
||||
test "with markdown formatting" do
|
||||
mario = insert(:user, nickname: "mario")
|
||||
luigi = insert(:user, nickname: "luigi")
|
||||
|
||||
{:ok, post} = CommonAPI.post(luigi, %{status: "Mama mia"})
|
||||
|
||||
activity = %{
|
||||
"type" => "Create",
|
||||
"actor" => mario.ap_id,
|
||||
"object" => %{
|
||||
"type" => "Note",
|
||||
"actor" => mario.ap_id,
|
||||
"content" => "<p>I'ma tired...</p>",
|
||||
"to" => [
|
||||
luigi.ap_id,
|
||||
Constants.as_public()
|
||||
],
|
||||
"inReplyTo" => Object.normalize(post).data["id"]
|
||||
}
|
||||
}
|
||||
|
||||
{:ok, %{"object" => %{"content" => filtered}}} = ForceMentionsInContent.filter(activity)
|
||||
|
||||
assert filtered ==
|
||||
"<p><span class=\"recipients-inline\"><span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{luigi.id}\" href=\"#{luigi.ap_id}\" rel=\"ugc\">@<span>luigi</span></a></span> </span>I'ma tired...</p>"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue