visibility: improve visibility functions since the SQL one is gone now

This commit is contained in:
Ariadne Conill 2019-08-26 04:39:00 +00:00
parent 079f1c3aa2
commit dd904ab8fa

View File

@ -14,7 +14,10 @@ defmodule Pleroma.Web.ActivityPub.Visibility do
def is_public?(%Object{data: data}), do: is_public?(data)
def is_public?(%Activity{data: data}), do: is_public?(data)
def is_public?(%{"directMessage" => true}), do: false
def is_public?(data), do: Pleroma.Constants.as_public() in (data["to"] ++ (data["cc"] || []))
def is_public?(%{"to" => to} = data), do: Pleroma.Constants.as_public() in (to ++ (data["cc"] || []))
def is_public?(%{"type" => "Create"}), do: false
def is_public?(%{"type" => _}), do: true
def is_public?(_), do: false
def is_private?(activity) do
with false <- is_public?(activity),
@ -53,7 +56,7 @@ defmodule Pleroma.Web.ActivityPub.Visibility do
def visible_for_user?(activity, user) do
x = [user.ap_id | user.following]
y = [activity.actor] ++ activity.data["to"] ++ (activity.data["cc"] || [])
y = [activity.actor] ++ activity.recipients
visible_for_user?(activity, nil) || Enum.any?(x, &(&1 in y))
end