ForceMentionsInContentTest: return mentions in a not terrible format

This commit is contained in:
Alex Gleason 2022-01-24 20:03:43 -06:00
parent c5a20c80c4
commit 267184b70e
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 29 additions and 15 deletions

View file

@ -50,7 +50,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ForceMentionsInContent do
added_mentions = added_mentions =
Enum.reduce(mention_users, "", fn {uri, user}, acc -> Enum.reduce(mention_users, "", fn {uri, user}, acc ->
unless uri in explicitly_mentioned_uris do unless uri in explicitly_mentioned_uris do
acc <> Formatter.mention_from_user(user) acc <> Formatter.mention_from_user(user, %{mentions_format: :compact}) <> " "
else else
acc acc
end end

View file

@ -8,17 +8,29 @@ defmodule Pleroma.Web.ActivityPub.MRF.ForceMentionsInContentTest do
use Pleroma.DataCase use Pleroma.DataCase
test "adds mentions to post content" do test "adds mentions to post content" do
users = %{ [lain, coolboymew, dielan, hakui, fence] = [
"lain@lain.com" => "https://lain.com/users/lain", insert(:user, ap_id: "https://lain.com/users/lain", nickname: "lain@lain.com", local: false),
"coolboymew@shitposter.club" => "https://shitposter.club/users/coolboymew", insert(:user,
"dielan@shitposter.club" => "https://shitposter.club/users/dielan", ap_id: "https://shitposter.club/users/coolboymew",
"hakui@tuusin.misono-ya.info" => "https://tuusin.misono-ya.info/users/hakui", nickname: "coolboymew@shitposter.club",
"fence@xyzzy.link" => "https://xyzzy.link/users/fence" local: false
} ),
insert(:user,
Enum.each(users, fn {nickname, ap_id} -> ap_id: "https://shitposter.club/users/dielan",
insert(:user, ap_id: ap_id, nickname: nickname, local: false) nickname: "dielan@shitposter.club",
end) local: false
),
insert(:user,
ap_id: "https://tuusin.misono-ya.info/users/hakui",
nickname: "hakui@tuusin.misono-ya.info",
local: false
),
insert(:user,
ap_id: "https://xyzzy.link/users/fence",
nickname: "fence@xyzzy.link",
local: false
)
]
object = File.read!("test/fixtures/soapbox_no_mentions_in_content.json") |> Jason.decode!() object = File.read!("test/fixtures/soapbox_no_mentions_in_content.json") |> Jason.decode!()
@ -29,6 +41,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.ForceMentionsInContentTest do
} }
{:ok, %{"object" => %{"content" => filtered}}} = ForceMentionsInContent.filter(activity) {:ok, %{"object" => %{"content" => filtered}}} = ForceMentionsInContent.filter(activity)
Enum.each(users, fn {nickname, _} -> assert filtered =~ nickname end)
assert filtered ==
"<span class=\"recipients-inline\"><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 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=\"#{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=\"#{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=\"#{fence.id}\" href=\"https://xyzzy.link/users/fence\" rel=\"ugc\">@<span>fence</span></a></span> </span><p>Haha yeah, you can control who you reply to.</p>"
end end
end end