aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/pleroma/web/activity_pub/mrf/no_placeholder_text_policy.ex7
-rw-r--r--test/pleroma/web/activity_pub/mrf/no_placeholder_text_policy_test.exs41
2 files changed, 46 insertions, 2 deletions
diff --git a/lib/pleroma/web/activity_pub/mrf/no_placeholder_text_policy.ex b/lib/pleroma/web/activity_pub/mrf/no_placeholder_text_policy.ex
index aab647d8e..f81e9e52a 100644
--- a/lib/pleroma/web/activity_pub/mrf/no_placeholder_text_policy.ex
+++ b/lib/pleroma/web/activity_pub/mrf/no_placeholder_text_policy.ex
@@ -7,13 +7,16 @@ defmodule Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicy do
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
@impl true
+ def history_awareness, do: :auto
+
+ @impl true
def filter(
%{
- "type" => "Create",
+ "type" => type,
"object" => %{"content" => content, "attachment" => _} = _child_object
} = object
)
- when content in [".", "<p>.</p>"] do
+ when type in ["Create", "Update"] and content in [".", "<p>.</p>"] do
{:ok, put_in(object, ["object", "content"], "")}
end
diff --git a/test/pleroma/web/activity_pub/mrf/no_placeholder_text_policy_test.exs b/test/pleroma/web/activity_pub/mrf/no_placeholder_text_policy_test.exs
index acc7c3566..3533c2bc8 100644
--- a/test/pleroma/web/activity_pub/mrf/no_placeholder_text_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/no_placeholder_text_policy_test.exs
@@ -4,6 +4,7 @@
defmodule Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicyTest do
use Pleroma.DataCase, async: true
+ alias Pleroma.Web.ActivityPub.MRF
alias Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicy
test "it clears content object" do
@@ -20,6 +21,46 @@ defmodule Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicyTest do
assert res["object"]["content"] == ""
end
+ test "history-aware" do
+ message = %{
+ "type" => "Create",
+ "object" => %{
+ "content" => ".",
+ "attachment" => "image",
+ "formerRepresentations" => %{
+ "orderedItems" => [%{"content" => ".", "attachment" => "image"}]
+ }
+ }
+ }
+
+ assert {:ok, res} = MRF.filter_one(NoPlaceholderTextPolicy, message)
+
+ assert %{
+ "content" => "",
+ "formerRepresentations" => %{"orderedItems" => [%{"content" => ""}]}
+ } = res["object"]
+ end
+
+ test "works with Updates" do
+ message = %{
+ "type" => "Update",
+ "object" => %{
+ "content" => ".",
+ "attachment" => "image",
+ "formerRepresentations" => %{
+ "orderedItems" => [%{"content" => ".", "attachment" => "image"}]
+ }
+ }
+ }
+
+ assert {:ok, res} = MRF.filter_one(NoPlaceholderTextPolicy, message)
+
+ assert %{
+ "content" => "",
+ "formerRepresentations" => %{"orderedItems" => [%{"content" => ""}]}
+ } = res["object"]
+ end
+
@messages [
%{
"type" => "Create",