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.SubchainPolicy do
7 alias Pleroma.Web.ActivityPub.MRF
11 @behaviour Pleroma.Web.ActivityPub.MRF
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 #{
31 MRF.filter(subchain, message)
38 def filter(message), do: {:ok, message}
41 def describe, do: {:ok, %{}}
44 def config_description do
47 related_policy: "Pleroma.Web.ActivityPub.MRF.SubchainPolicy",
48 label: "MRF Subchain",
50 "This policy processes messages through an alternate pipeline when a given message matches certain criteria." <>
51 " All criteria are configured as a map of regular expressions to lists of policy modules.",
55 type: {:map, {:list, :string}},
56 description: "Matches a series of regular expressions against the actor field",
59 ~r/https:\/\/example.com/s => [Pleroma.Web.ActivityPub.MRF.DropPolicy]