Merge remote-tracking branch 'pleroma/develop' into feature/disable-account
[akkoma] / lib / pleroma / web / activity_pub / mrf / reject_non_public.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublic do
6 alias Pleroma.User
7 @behaviour Pleroma.Web.ActivityPub.MRF
8
9 @impl true
10 def filter(%{"type" => "Create"} = object) do
11 user = User.get_cached_by_ap_id(object["actor"])
12 public = "https://www.w3.org/ns/activitystreams#Public"
13
14 # Determine visibility
15 visibility =
16 cond do
17 public in object["to"] -> "public"
18 public in object["cc"] -> "unlisted"
19 user.follower_address in object["to"] -> "followers"
20 true -> "direct"
21 end
22
23 policy = Pleroma.Config.get(:mrf_rejectnonpublic)
24
25 case visibility do
26 "public" ->
27 {:ok, object}
28
29 "unlisted" ->
30 {:ok, object}
31
32 "followers" ->
33 with true <- Keyword.get(policy, :allow_followersonly) do
34 {:ok, object}
35 else
36 _e -> {:reject, nil}
37 end
38
39 "direct" ->
40 with true <- Keyword.get(policy, :allow_direct) do
41 {:ok, object}
42 else
43 _e -> {:reject, nil}
44 end
45 end
46 end
47
48 @impl true
49 def filter(object), do: {:ok, object}
50 end