From 267184b70e587a3e6301d3a01bd16fd465bc0f68 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 24 Jan 2022 20:03:43 -0600 Subject: ForceMentionsInContentTest: return mentions in a not terrible format --- .../activity_pub/mrf/force_mentions_in_content.ex | 6 ++-- .../mrf/force_mentions_in_content_test.exs | 38 +++++++++++++++------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/lib/pleroma/web/activity_pub/mrf/force_mentions_in_content.ex b/lib/pleroma/web/activity_pub/mrf/force_mentions_in_content.ex index a458bed31..1d750d4c2 100644 --- a/lib/pleroma/web/activity_pub/mrf/force_mentions_in_content.ex +++ b/lib/pleroma/web/activity_pub/mrf/force_mentions_in_content.ex @@ -41,7 +41,7 @@ def filter(%{"type" => "Create", "object" => %{"type" => "Note", "to" => to}} = mention_users = to - |> Enum.map(& {&1, User.get_cached_by_ap_id(&1)}) + |> Enum.map(&{&1, User.get_cached_by_ap_id(&1)}) |> Enum.reject(fn {_, user} -> is_nil(user) end) |> Enum.into(%{}) @@ -50,7 +50,7 @@ def filter(%{"type" => "Create", "object" => %{"type" => "Note", "to" => to}} = added_mentions = Enum.reduce(mention_users, "", fn {uri, user}, acc -> unless uri in explicitly_mentioned_uris do - acc <> Formatter.mention_from_user(user) + acc <> Formatter.mention_from_user(user, %{mentions_format: :compact}) <> " " else acc end @@ -58,7 +58,7 @@ def filter(%{"type" => "Create", "object" => %{"type" => "Note", "to" => to}} = content = if added_mentions != "", - do: "#{added_mentions} " <> content, + do: "#{added_mentions}" <> content, else: content {:ok, put_in(object["object"]["content"], content)} diff --git a/test/pleroma/web/activity_pub/mrf/force_mentions_in_content_test.exs b/test/pleroma/web/activity_pub/mrf/force_mentions_in_content_test.exs index 090bdc35e..3c40887c4 100644 --- a/test/pleroma/web/activity_pub/mrf/force_mentions_in_content_test.exs +++ b/test/pleroma/web/activity_pub/mrf/force_mentions_in_content_test.exs @@ -8,17 +8,29 @@ defmodule Pleroma.Web.ActivityPub.MRF.ForceMentionsInContentTest do use Pleroma.DataCase test "adds mentions to post content" do - users = %{ - "lain@lain.com" => "https://lain.com/users/lain", - "coolboymew@shitposter.club" => "https://shitposter.club/users/coolboymew", - "dielan@shitposter.club" => "https://shitposter.club/users/dielan", - "hakui@tuusin.misono-ya.info" => "https://tuusin.misono-ya.info/users/hakui", - "fence@xyzzy.link" => "https://xyzzy.link/users/fence" - } - - Enum.each(users, fn {nickname, ap_id} -> - insert(:user, ap_id: ap_id, nickname: nickname, local: false) - end) + [lain, coolboymew, dielan, hakui, fence] = [ + insert(:user, ap_id: "https://lain.com/users/lain", nickname: "lain@lain.com", local: false), + insert(:user, + ap_id: "https://shitposter.club/users/coolboymew", + nickname: "coolboymew@shitposter.club", + local: false + ), + insert(:user, + ap_id: "https://shitposter.club/users/dielan", + nickname: "dielan@shitposter.club", + 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!() @@ -29,6 +41,8 @@ test "adds mentions to post content" do } {:ok, %{"object" => %{"content" => filtered}}} = ForceMentionsInContent.filter(activity) - Enum.each(users, fn {nickname, _} -> assert filtered =~ nickname end) + + assert filtered == + "@lain @coolboymew @dielan @hakui @fence

Haha yeah, you can control who you reply to.

" end end -- cgit v1.2.3