formatting
[akkoma] / lib / pleroma / web / activity_pub / mrf / subchain_policy.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.MRF.SubchainPolicy do
6 alias Pleroma.Config
7 alias Pleroma.Web.ActivityPub.MRF
8
9 require Logger
10
11 @behaviour MRF
12
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}
17 else
18 _e -> {:error, :notfound}
19 end
20 end
21
22 @impl true
23 def filter(%{"actor" => actor} = message) do
24 with {:ok, match, subchain} <- lookup_subchain(actor) do
25 Logger.debug(
26 "[SubchainPolicy] Matched #{actor} against #{inspect(match)} with subchain #{
27 inspect(subchain)
28 }"
29 )
30
31 subchain
32 |> MRF.filter(message)
33 else
34 _e -> {:ok, message}
35 end
36 end
37
38 @impl true
39 def filter(message), do: {:ok, message}
40 end