Merge remote-tracking branch 'upstream/develop' into by-approval
[akkoma] / lib / pleroma / web / activity_pub / mrf / mention_policy.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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
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 end