total rebase
[anni] / static / modules / auto_untagger_policy.ex
1 defmodule Pleroma.Web.ActivityPub.MRF.AutoUntaggerPolicy do
2   @moduledoc "Automatically untags all local users from posts originating from specified instances"
3   @behaviour Pleroma.Web.ActivityPub.MRF.Policy
4
5   require Pleroma.Constants
6   alias Pleroma.Config
7
8   @impl true
9   def filter(
10         %{
11           "type" => "Create",
12           "to" => to,
13           "cc" => cc,
14           "actor" => actor,
15           "object" => object
16         } = message
17       ) do
18
19     local = Config.get([Pleroma.Web.Endpoint, :url, :host])
20     if URI.parse(actor).authority in Config.get([:mrf_auto_untagger, :domains]) do
21       object =
22         object
23         |> Map.put("to", Enum.filter(to, fn x -> URI.parse(x).authority != local end))
24         |> Map.put("cc", Enum.filter(cc, fn x -> URI.parse(x).authority != local end))
25         |> Map.put("tag", Enum.filter(object["tag"], fn x -> URI.parse(x["href"]).authority != local end))
26
27       message =
28         message
29         |> Map.put("to", Enum.filter(to, fn x -> URI.parse(x).authority != local end))
30         |> Map.put("cc", Enum.filter(cc, fn x -> URI.parse(x).authority != local end))
31         |> Map.put("object", object)
32
33       {:ok, message}
34     else
35       {:ok, message}
36     end
37   end
38
39   @impl true
40   def filter(message) do
41     {:ok, message}
42   end
43
44   @impl true
45   def describe, do: {:ok, %{}}
46
47   @impl true
48   def config_description do
49     %{
50       key: :mrf_auto_untagger,
51       related_policy: "Pleroma.Web.ActivityPub.MRF.AutoUntaggerPolicy",
52       label: "Autountagger policy",
53       description: "Automatically untags all local users from posts originating from specified instances",
54       children: [
55         %{
56           key: :domains,
57           type: {:list, :string},
58           label: "List of affected instance domains",
59           suggestions: ["freespeechextremist.com"]
60         }
61       ]
62     }
63   end
64 end