1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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
10 def filter(%{"type" => "Undo", "object" => child_message} = message) do
11 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]),
23 Enum.empty?(accepted_vocabulary) || Enum.member?(accepted_vocabulary, message_type),
25 length(rejected_vocabulary) > 0 && Enum.member?(rejected_vocabulary, message_type),
26 {:ok, _} <- filter(message["object"]) do
33 def filter(message), do: {:ok, message}
36 do: {:ok, %{mrf_vocabulary: Pleroma.Config.get(:mrf_vocabulary) |> Enum.into(%{})}}