aboutsummaryrefslogtreecommitdiff
path: root/static/modules/auto_untagger_policy.ex
blob: 525eb026c49c0ab66e91d6726346ebb9d55ec01b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
defmodule Pleroma.Web.ActivityPub.MRF.AutoUntaggerPolicy do
  @moduledoc "Automatically untags all local users from posts originating from specified instances"
  @behaviour Pleroma.Web.ActivityPub.MRF.Policy

  require Pleroma.Constants
  alias Pleroma.Config

  @impl true
  def filter(
        %{
          "type" => "Create",
          "to" => to,
          "cc" => cc,
          "actor" => actor,
          "object" => object
        } = message
      ) do

    local = Config.get([Pleroma.Web.Endpoint, :url, :host])
    if URI.parse(actor).authority in Config.get([:mrf_auto_untagger, :domains]) do
      object =
        object
        |> Map.put("to", Enum.filter(to, fn x -> URI.parse(x).authority != local end))
        |> Map.put("cc", Enum.filter(cc, fn x -> URI.parse(x).authority != local end))
        |> Map.put("tag", Enum.filter(object["tag"], fn x -> URI.parse(x["href"]).authority != local end))

      message =
        message
        |> Map.put("to", Enum.filter(to, fn x -> URI.parse(x).authority != local end))
        |> Map.put("cc", Enum.filter(cc, fn x -> URI.parse(x).authority != local end))
        |> Map.put("object", object)

      {:ok, message}
    else
      {:ok, message}
    end
  end

  @impl true
  def filter(message) do
    {:ok, message}
  end

  @impl true
  def describe, do: {:ok, %{}}

  @impl true
  def config_description do
    %{
      key: :mrf_auto_untagger,
      related_policy: "Pleroma.Web.ActivityPub.MRF.AutoUntaggerPolicy",
      label: "Autountagger policy",
      description: "Automatically untags all local users from posts originating from specified instances",
      children: [
        %{
          key: :domains,
          type: {:list, :string},
          label: "List of affected instance domains",
          suggestions: ["freespeechextremist.com"]
        }
      ]
    }
  end
end