aboutsummaryrefslogtreecommitdiff
path: root/static/modules/lock_smasher.ex
blob: a81c20851945585378473cadf0d40605baf98b3c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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