MRF: create MRF.Policy behaviour separate from MRF module
[akkoma] / lib / pleroma / web / activity_pub / mrf / no_placeholder_text_policy.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicy do
6 @moduledoc "Ensure no content placeholder is present (such as the dot from mastodon)"
7 @behaviour Pleroma.Web.ActivityPub.MRF.Policy
8
9 @impl true
10 def filter(
11 %{
12 "type" => "Create",
13 "object" => %{"content" => content, "attachment" => _} = _child_object
14 } = object
15 )
16 when content in [".", "<p>.</p>"] do
17 {:ok, put_in(object, ["object", "content"], "")}
18 end
19
20 @impl true
21 def filter(object), do: {:ok, object}
22
23 @impl true
24 def describe, do: {:ok, %{}}
25 end