8aa4f347f15619986d8bfa497dd3d8c7c1387ffd
[anni] / lib / pleroma / web / activity_pub / mrf / mention_policy.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicy do
6   @moduledoc "Block messages which mention a user"
7
8   @behaviour Pleroma.Web.ActivityPub.MRF.Policy
9
10   @impl true
11   def filter(%{"type" => "Create"} = message) do
12     reject_actors = Pleroma.Config.get([:mrf_mention, :actors], [])
13     recipients = (message["to"] || []) ++ (message["cc"] || [])
14
15     if rejected_mention =
16          Enum.find(recipients, fn recipient -> Enum.member?(reject_actors, recipient) end) do
17       {:reject, "[MentionPolicy] Rejected for mention of #{rejected_mention}"}
18     else
19       {:ok, message}
20     end
21   end
22
23   @impl true
24   def filter(message), do: {:ok, message}
25
26   @impl true
27   def describe, do: {:ok, %{}}
28
29   @impl true
30   def config_description do
31     %{
32       key: :mrf_mention,
33       related_policy: "Pleroma.Web.ActivityPub.MRF.MentionPolicy",
34       label: "MRF Mention",
35       description: "Block messages which mention a specific user",
36       children: [
37         %{
38           key: :actors,
39           type: {:list, :string},
40           description: "A list of actors for which any post mentioning them will be dropped",
41           suggestions: ["actor1", "actor2"]
42         }
43       ]
44     }
45   end
46 end