diff options
| author | dcc <dcc@logografos.com> | 2024-02-16 17:19:33 -0800 |
|---|---|---|
| committer | dcc <dcc@logografos.com> | 2024-02-16 17:19:33 -0800 |
| commit | ea33a0d3427f8b30b82a6ddbc0ff7429cfaf8d91 (patch) | |
| tree | de6626e4308723941e637df6ceade347f4252568 /static/modules | |
| parent | 6b975ebdc903ae91ecfafc1c9f6daf57d7945f7a (diff) | |
| download | anni-ea33a0d3427f8b30b82a6ddbc0ff7429cfaf8d91.tar.gz anni-ea33a0d3427f8b30b82a6ddbc0ff7429cfaf8d91.tar.bz2 anni-ea33a0d3427f8b30b82a6ddbc0ff7429cfaf8d91.zip | |
Nothing much just a build up of things
Diffstat (limited to 'static/modules')
| -rw-r--r-- | static/modules/auto_untagger_policy.ex | 64 | ||||
| -rw-r--r-- | static/modules/inline_quote_policy.ex | 77 | ||||
| -rw-r--r-- | static/modules/lock_smasher.ex | 63 |
3 files changed, 204 insertions, 0 deletions
diff --git a/static/modules/auto_untagger_policy.ex b/static/modules/auto_untagger_policy.ex new file mode 100644 index 0000000..525eb02 --- /dev/null +++ b/static/modules/auto_untagger_policy.ex @@ -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 diff --git a/static/modules/inline_quote_policy.ex b/static/modules/inline_quote_policy.ex new file mode 100644 index 0000000..b7a01c2 --- /dev/null +++ b/static/modules/inline_quote_policy.ex @@ -0,0 +1,77 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.MRF.InlineQuotePolicy do + @moduledoc "Force a quote line into the message content." + @behaviour Pleroma.Web.ActivityPub.MRF.Policy + + defp build_inline_quote(template, url) do + quote_line = String.replace(template, "{url}", "<a href=\"#{url}\">#{url}</a>") + + "<span class=\"quote-inline\"><br/><br/>#{quote_line}</span>" + end + + defp has_inline_quote?(content, quote_url) do + cond do + # Does the quote URL exist in the content? + content =~ quote_url -> true + # Does the content already have a .quote-inline span? + content =~ "<span class=\"quote-inline\">" -> true + # No inline quote found + true -> false + end + end + + defp filter_object(%{"quoteUrl" => quote_url} = object) do + content = object["content"] || "" + + if has_inline_quote?(content, quote_url) do + object + else + template = Pleroma.Config.get([:mrf_inline_quote, :template]) + + content = + if String.ends_with?(content, "</p>"), + do: + String.trim_trailing(content, "</p>") <> + build_inline_quote(template, quote_url) <> "</p>", + else: content <> build_inline_quote(template, quote_url) + + Map.put(object, "content", content) + end + end + + @impl true + def filter(%{"object" => %{"quoteUrl" => _} = object} = activity) do + {:ok, Map.put(activity, "object", filter_object(object))} + end + + @impl true + def filter(object), do: {:ok, object} + + @impl true + def describe, do: {:ok, %{}} + + @impl Pleroma.Web.ActivityPub.MRF.Policy + def history_awareness, do: :auto + + @impl true + def config_description do + %{ + key: :mrf_inline_quote, + related_policy: "Pleroma.Web.ActivityPub.MRF.InlineQuotePolicy", + label: "MRF Inline Quote Policy", + description: "Force quote url to appear in post content.", + children: [ + %{ + key: :template, + type: :string, + description: + "The template to append to the post. `{url}` will be replaced with the actual link to the quoted post.", + suggestions: ["<bdi>RT:</bdi> {url}"] + } + ] + } + end +end diff --git a/static/modules/lock_smasher.ex b/static/modules/lock_smasher.ex new file mode 100644 index 0000000..a81c208 --- /dev/null +++ b/static/modules/lock_smasher.ex @@ -0,0 +1,63 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +# Fuck you falaichte +defmodule Pleroma.Web.ActivityPub.MRF.LockSmasher do + alias Pleroma.Config + alias Pleroma.User + + @behaviour Pleroma.Web.ActivityPub.MRF.Policy + + require Pleroma.Constants + + @impl true + def filter( + %{ + "type" => "Create", + "to" => to, + "cc" => cc, + "actor" => actor, + "object" => object + } = message + ) do + actor_info = URI.parse(actor) + user = User.get_cached_by_ap_id(actor) + instance_domain = Config.get([Pleroma.Web.Endpoint, :url, :host]) + + # Determine visibility + visibility = + cond do + Pleroma.Constants.as_public() in to -> "public" + Pleroma.Constants.as_public() in cc -> "unlisted" + user.follower_address in to -> "followers" + true -> "direct" + end + + if visibility in ["unlisted", "followers"] and actor_info.host != instance_domain do + to = List.delete(to, user.follower_address) ++ [Pleroma.Constants.as_public()] + cc = List.delete(cc, Pleroma.Constants.as_public()) ++ [user.follower_address] + + object = + object + |> Map.put("to", to) + |> Map.put("cc", cc) + + message = + message + |> Map.put("to", to) + |> Map.put("cc", cc) + |> Map.put("object", object) + + {:ok, message} + else + {:ok, message} + end + + end + + @impl true + def filter(message), do: {:ok, message} + + @impl true + def describe, do: {:ok, %{}} +end |
