Merge branch 'exclude-reblogs-from-admin-api-by-default' into 'develop'
[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 Enum.any?(recipients, fn recipient -> Enum.member?(reject_actors, recipient) end) do
16 {:reject, nil}
17 else
18 {:ok, message}
19 end
20 end
21
22 @impl true
23 def filter(message), do: {:ok, message}
24
25 @impl true
26 def describe, do: {:ok, %{}}
27 end