aboutsummaryrefslogtreecommitdiff
path: root/static/modules/lock_smasher.ex
diff options
context:
space:
mode:
authordcc <dcc@logografos.com>2024-02-16 17:19:33 -0800
committerdcc <dcc@logografos.com>2024-02-16 17:19:33 -0800
commitea33a0d3427f8b30b82a6ddbc0ff7429cfaf8d91 (patch)
treede6626e4308723941e637df6ceade347f4252568 /static/modules/lock_smasher.ex
parent6b975ebdc903ae91ecfafc1c9f6daf57d7945f7a (diff)
downloadanni-ea33a0d3427f8b30b82a6ddbc0ff7429cfaf8d91.tar.gz
anni-ea33a0d3427f8b30b82a6ddbc0ff7429cfaf8d91.tar.bz2
anni-ea33a0d3427f8b30b82a6ddbc0ff7429cfaf8d91.zip
Nothing much just a build up of things
Diffstat (limited to 'static/modules/lock_smasher.ex')
-rw-r--r--static/modules/lock_smasher.ex63
1 files changed, 63 insertions, 0 deletions
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