1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicy do
6 @moduledoc "Filter messages which belong to certain activity vocabularies"
8 @behaviour Pleroma.Web.ActivityPub.MRF
11 def filter(%{"type" => "Undo", "object" => child_message} = message) do
12 with {:ok, _} <- filter(child_message) do
19 def filter(%{"type" => message_type} = message) do
20 with accepted_vocabulary <- Pleroma.Config.get([:mrf_vocabulary, :accept]),
21 rejected_vocabulary <- Pleroma.Config.get([:mrf_vocabulary, :reject]),
24 Enum.empty?(accepted_vocabulary) || Enum.member?(accepted_vocabulary, message_type)},
27 length(rejected_vocabulary) > 0 && Enum.member?(rejected_vocabulary, message_type)},
28 {:ok, _} <- filter(message["object"]) do
32 {:accepted, _} -> {:reject, "[VocabularyPolicy] #{message_type} not in accept list"}
33 {:rejected, _} -> {:reject, "[VocabularyPolicy] #{message_type} in reject list"}
34 _ -> {:reject, "[VocabularyPolicy]"}
38 def filter(message), do: {:ok, message}
42 do: {:ok, %{mrf_vocabulary: Pleroma.Config.get(:mrf_vocabulary) |> Enum.into(%{})}}
45 def config_description do
48 related_policy: "Pleroma.Web.ActivityPub.MRF.VocabularyPolicy",
49 label: "MRF Vocabulary",
50 description: "Filter messages which belong to certain activity vocabularies",
54 type: {:list, :string},
56 "A list of ActivityStreams terms to accept. If empty, all supported messages are accepted.",
57 suggestions: ["Create", "Follow", "Mention", "Announce", "Like"]
61 type: {:list, :string},
63 "A list of ActivityStreams terms to reject. If empty, no messages are rejected.",
64 suggestions: ["Create", "Follow", "Mention", "Announce", "Like"]