summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Gleason <alex@alexgleason.me>2022-01-26 21:24:26 -0600
committerAlex Gleason <alex@alexgleason.me>2022-01-26 21:24:26 -0600
commit27cb3d62738f6ea174994f72688497db49cef754 (patch)
tree2f094d7fc3208eb34a08bbbef8d628bb023e7757
parent2bab9dd17529136e497230e286230bb6ae09e595 (diff)
ForceMentionsInContent: don't apply it to top-level posts
-rw-r--r--lib/pleroma/web/activity_pub/mrf/force_mentions_in_content.ex9
-rw-r--r--test/pleroma/web/activity_pub/mrf/force_mentions_in_content_test.exs25
2 files changed, 32 insertions, 2 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 71c240727..715771d9d 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
@@ -72,8 +72,13 @@ defmodule Pleroma.Web.ActivityPub.MRF.ForceMentionsInContent do
end
@impl true
- def filter(%{"type" => "Create", "object" => %{"type" => "Note", "to" => to}} = object)
- when is_list(to) do
+ def filter(
+ %{
+ "type" => "Create",
+ "object" => %{"type" => "Note", "to" => to, "inReplyTo" => in_reply_to}
+ } = object
+ )
+ when is_list(to) and is_binary(in_reply_to) do
# image-only posts from pleroma apparently reach this MRF without the content field
content = object["object"]["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 589e8fdfb..6bcf75a92 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
@@ -109,4 +109,29 @@ defmodule Pleroma.Web.ActivityPub.MRF.ForceMentionsInContentTest do
{:ok, %{"object" => %{"content" => filtered}}} = ForceMentionsInContent.filter(activity)
assert filtered == "I'ma tired..."
end
+
+ test "don't mention in top-level posts" do
+ mario = insert(:user, nickname: "mario")
+ luigi = insert(:user, nickname: "luigi")
+
+ {:ok, post} = CommonAPI.post(mario, %{status: "Letsa go"})
+
+ activity = %{
+ "type" => "Create",
+ "actor" => mario.ap_id,
+ "object" => %{
+ "type" => "Note",
+ "actor" => mario.ap_id,
+ "content" => "Mama mia!",
+ "to" => [
+ luigi.ap_id,
+ Constants.as_public()
+ ],
+ "quoteUrl" => Object.normalize(post).data["id"]
+ }
+ }
+
+ {:ok, %{"object" => %{"content" => filtered}}} = ForceMentionsInContent.filter(activity)
+ assert filtered == "Mama mia!"
+ end
end