2019-07-30 16:40:59 +02:00
|
|
|
# Portions of this file are derived from Pleroma:
|
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/activity_pub/visibility.ex
|
|
|
|
|
|
|
|
defmodule Mobilizon.Service.ActivityPub.Visibility do
|
|
|
|
@moduledoc """
|
|
|
|
Utility functions related to content visibility
|
|
|
|
"""
|
2019-09-13 01:35:03 +02:00
|
|
|
|
2019-11-15 18:36:47 +01:00
|
|
|
alias Mobilizon.Events.Comment
|
2019-09-22 09:24:18 +02:00
|
|
|
alias Mobilizon.Service.ActivityPub.Activity
|
2019-07-30 16:40:59 +02:00
|
|
|
|
|
|
|
@public "https://www.w3.org/ns/activitystreams#Public"
|
|
|
|
|
|
|
|
@spec is_public?(Activity.t() | map()) :: boolean()
|
|
|
|
def is_public?(%{data: %{"type" => "Tombstone"}}), do: false
|
|
|
|
def is_public?(%{data: data}), do: is_public?(data)
|
|
|
|
def is_public?(%Activity{data: data}), do: is_public?(data)
|
2019-12-03 11:29:51 +01:00
|
|
|
|
|
|
|
def is_public?(data) when is_map(data),
|
|
|
|
do: @public in (Map.get(data, "to", []) ++ Map.get(data, "cc", []))
|
|
|
|
|
2019-11-15 18:36:47 +01:00
|
|
|
def is_public?(%Comment{deleted_at: deleted_at}), do: !is_nil(deleted_at)
|
2019-07-30 16:40:59 +02:00
|
|
|
def is_public?(err), do: raise(ArgumentError, message: "Invalid argument #{inspect(err)}")
|
|
|
|
end
|