1 defmodule Pleroma.Web.ActivityPub.Visibility do
6 def is_public?(%Object{data: %{"type" => "Tombstone"}}), do: false
7 def is_public?(%Object{data: data}), do: is_public?(data)
8 def is_public?(%Activity{data: data}), do: is_public?(data)
9 def is_public?(%{"directMessage" => true}), do: false
11 def is_public?(data) do
12 "https://www.w3.org/ns/activitystreams#Public" in (data["to"] ++ (data["cc"] || []))
15 def is_private?(activity) do
16 unless is_public?(activity) do
17 follower_address = User.get_cached_by_ap_id(activity.data["actor"]).follower_address
18 Enum.any?(activity.data["to"], &(&1 == follower_address))
24 def is_direct?(%Activity{data: %{"directMessage" => true}}), do: true
25 def is_direct?(%Object{data: %{"directMessage" => true}}), do: true
27 def is_direct?(activity) do
28 !is_public?(activity) && !is_private?(activity)
31 def visible_for_user?(activity, nil) do
35 def visible_for_user?(activity, user) do
36 x = [user.ap_id | user.following]
37 y = [activity.actor] ++ activity.data["to"] ++ (activity.data["cc"] || [])
38 visible_for_user?(activity, nil) || Enum.any?(x, &(&1 in y))
42 def entire_thread_visible_for_user?(nil, _user), do: false
45 def entire_thread_visible_for_user?(
46 %Activity{data: %{"object" => %{"inReplyTo" => parent_id}}} = tail,
49 when is_binary(parent_id) do
50 parent = Activity.get_in_reply_to_activity(tail)
51 visible_for_user?(tail, user) && entire_thread_visible_for_user?(parent, user)
55 def entire_thread_visible_for_user?(tail, user), do: visible_for_user?(tail, user)