e3fcc44472b15f408b8baf6785394feaf3b04477
[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(object) do
7 if object["type"] == "Create" do
8 user = User.get_by_ap_id(object["actor"])
9 public = "https://www.w3.org/ns/activitystreams#Public"
10
11 # Determine visibility
12 visibility =
13 cond do
14 public in object["to"] -> "public"
15 public in object["cc"] -> "unlisted"
16 user.follower_address in object["to"] -> "followers"
17 true -> "direct"
18 end
19
20 {flag, object_out} =
21 case visibility do
22 "public" -> {:ok, object}
23 "unlisted" -> {:ok, object}
24 _ -> {:reject, nil}
25 end
26
27 {flag, object_out}
28 else
29 {:ok, object}
30 end
31 end
32 end