activitypub: short-circuit is_public?() with directMessage flag check

This commit is contained in:
William Pitcock 2019-01-20 02:30:29 +00:00
parent cf3099231d
commit aa37313416
1 changed files with 4 additions and 0 deletions

View File

@ -800,6 +800,7 @@ def fetch_and_contain_remote_object_from_id(id) do
def is_public?(%Object{data: %{"type" => "Tombstone"}}), do: false def is_public?(%Object{data: %{"type" => "Tombstone"}}), do: false
def is_public?(%Object{data: data}), do: is_public?(data) def is_public?(%Object{data: data}), do: is_public?(data)
def is_public?(%Activity{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 def is_public?(data) do
"https://www.w3.org/ns/activitystreams#Public" in (data["to"] ++ (data["cc"] || [])) "https://www.w3.org/ns/activitystreams#Public" in (data["to"] ++ (data["cc"] || []))
@ -809,6 +810,9 @@ def is_private?(activity) do
!is_public?(activity) && Enum.any?(activity.data["to"], &String.contains?(&1, "/followers")) !is_public?(activity) && Enum.any?(activity.data["to"], &String.contains?(&1, "/followers"))
end end
def is_direct?(%Activity{data: %{"directMessage" => true}}), do: true
def is_direct?(%Object{data: %{"directMessage" => true}}), do: true
def is_direct?(activity) do def is_direct?(activity) do
!is_public?(activity) && !is_private?(activity) !is_public?(activity) && !is_private?(activity)
end end