Nothing much just a build up of things
[anni] / static / modules / auto_untagger_policy.ex
diff --git a/static/modules/auto_untagger_policy.ex b/static/modules/auto_untagger_policy.ex
new file mode 100644 (file)
index 0000000..525eb02
--- /dev/null
@@ -0,0 +1,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