total rebase
[anni] / static / modules / lock_smasher.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4 # Fuck you falaichte
5 defmodule Pleroma.Web.ActivityPub.MRF.LockSmasher do
6   alias Pleroma.Config
7   alias Pleroma.User
8
9   @behaviour Pleroma.Web.ActivityPub.MRF.Policy
10
11   require Pleroma.Constants
12
13   @impl true
14   def filter(
15         %{
16           "type" => "Create",
17           "to" => to,
18           "cc" => cc,
19           "actor" => actor,
20           "object" => object
21         } = message
22       ) do
23     actor_info = URI.parse(actor)
24     user = User.get_cached_by_ap_id(actor)
25     instance_domain = Config.get([Pleroma.Web.Endpoint, :url, :host])
26
27     # Determine visibility
28     visibility =
29       cond do
30         Pleroma.Constants.as_public() in to -> "public"
31         Pleroma.Constants.as_public() in cc -> "unlisted"
32         user.follower_address in to -> "followers"
33         true -> "direct"
34       end
35
36     if visibility in ["unlisted", "followers"] and actor_info.host != instance_domain do
37       to = List.delete(to, user.follower_address) ++ [Pleroma.Constants.as_public()]
38       cc = List.delete(cc, Pleroma.Constants.as_public()) ++ [user.follower_address]
39
40       object =
41         object
42         |> Map.put("to", to)
43         |> Map.put("cc", cc)
44
45       message =
46         message
47         |> Map.put("to", to)
48         |> Map.put("cc", cc)
49         |> Map.put("object", object)
50
51       {:ok, message}
52     else
53       {:ok, message}
54     end
55
56   end
57
58   @impl true
59   def filter(message), do: {:ok, message}
60
61   @impl true
62   def describe, do: {:ok, %{}}
63 end