6272840838dfbf8740aa0bf6f299812b878b14db
[akkoma] / lib / pleroma / web / activity_pub / mrf / reject_non_public.ex
1 defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublic do
2 alias Pleroma.User
3 @behaviour Pleroma.Web.ActivityPub.MRF
4
5 @impl true
6 def filter(%{"type" => "Create"} = object) do
7 user = User.get_cached_by_ap_id(object["actor"])
8 public = "https://www.w3.org/ns/activitystreams#Public"
9
10 # Determine visibility
11 visibility =
12 cond do
13 public in object["to"] -> "public"
14 public in object["cc"] -> "unlisted"
15 user.follower_address in object["to"] -> "followers"
16 true -> "direct"
17 end
18
19 policy = Pleroma.Config.get(:mrf_rejectnonpublic)
20
21 case visibility do
22 "public" ->
23 {:ok, object}
24
25 "unlisted" ->
26 {:ok, object}
27
28 "followers" ->
29 with true <- Keyword.get(policy, :allow_followersonly) do
30 {:ok, object}
31 else
32 _e -> {:reject, nil}
33 end
34
35 "direct" ->
36 with true <- Keyword.get(policy, :allow_direct) do
37 {:ok, object}
38 else
39 _e -> {:reject, nil}
40 end
41 end
42 end
43
44 @impl true
45 def filter(object), do: {:ok, object}
46 end