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