1 defmodule Pleroma.Web.ActivityPub.Visibility do
7 def is_public?(%Object{data: %{"type" => "Tombstone"}}), do: false
8 def is_public?(%Object{data: data}), do: is_public?(data)
9 def is_public?(%Activity{data: data}), do: is_public?(data)
10 def is_public?(%{"directMessage" => true}), do: false
12 def is_public?(data) do
13 "https://www.w3.org/ns/activitystreams#Public" in (data["to"] ++ (data["cc"] || []))
16 def is_private?(activity) do
17 with false <- is_public?(activity),
18 %User{follower_address: follower_address} <-
19 User.get_cached_by_ap_id(activity.data["actor"]) do
20 follower_address in activity.data["to"]
26 def is_direct?(%Activity{data: %{"directMessage" => true}}), do: true
27 def is_direct?(%Object{data: %{"directMessage" => true}}), do: true
29 def is_direct?(activity) do
30 !is_public?(activity) && !is_private?(activity)
33 def visible_for_user?(activity, nil) do
37 def visible_for_user?(activity, user) do
38 x = [user.ap_id | user.following]
39 y = [activity.actor] ++ activity.data["to"] ++ (activity.data["cc"] || [])
40 visible_for_user?(activity, nil) || Enum.any?(x, &(&1 in y))
43 def entire_thread_visible_for_user?(%Activity{} = activity, %User{} = user) do
44 {:ok, %{rows: [[result]]}} =
45 Ecto.Adapters.SQL.query(Repo, "SELECT thread_visibility($1, $2)", [
53 def get_visibility(object) do
54 public = "https://www.w3.org/ns/activitystreams#Public"
55 to = object.data["to"] || []
56 cc = object.data["cc"] || []
65 # this should use the sql for the object's activity
66 Enum.any?(to, &String.contains?(&1, "/followers")) ->