From ea33a0d3427f8b30b82a6ddbc0ff7429cfaf8d91 Mon Sep 17 00:00:00 2001 From: dcc Date: Fri, 16 Feb 2024 17:19:33 -0800 Subject: Nothing much just a build up of things --- static/modules/lock_smasher.ex | 63 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 static/modules/lock_smasher.ex (limited to 'static/modules/lock_smasher.ex') 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 +# 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 -- cgit v1.2.3