1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.MRF.SubchainPolicy do
7 alias Pleroma.Web.ActivityPub.MRF
11 @behaviour Pleroma.Web.ActivityPub.MRF.Policy
13 defp lookup_subchain(actor) do
14 with matches <- Config.get([:mrf_subchain, :match_actor]),
15 {match, subchain} <- Enum.find(matches, fn {k, _v} -> String.match?(actor, k) end) do
16 {:ok, match, subchain}
18 _e -> {:error, :notfound}
23 def filter(%{"actor" => actor} = message) do
24 with {:ok, match, subchain} <- lookup_subchain(actor) do
26 "[SubchainPolicy] Matched #{actor} against #{inspect(match)} with subchain #{inspect(subchain)}"
29 MRF.filter(subchain, message)
36 def filter(message), do: {:ok, message}
39 def describe, do: {:ok, %{}}
42 def config_description do
45 related_policy: "Pleroma.Web.ActivityPub.MRF.SubchainPolicy",
46 label: "MRF Subchain",
48 "This policy processes messages through an alternate pipeline when a given message matches certain criteria." <>
49 " All criteria are configured as a map of regular expressions to lists of policy modules.",
53 type: {:map, {:list, :string}},
54 description: "Matches a series of regular expressions against the actor field",
57 ~r/https:\/\/example.com/s => [Pleroma.Web.ActivityPub.MRF.DropPolicy]