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
|
|
|
|
|
2020-01-22 02:14:42 +01:00
|
|
|
defmodule Mobilizon.Federation.ActivityPub.Visibility do
|
2019-07-30 16:40:59 +02:00
|
|
|
@moduledoc """
|
|
|
|
Utility functions related to content visibility
|
|
|
|
"""
|
2019-09-13 01:35:03 +02:00
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
alias Mobilizon.Discussions.Comment
|
2020-01-22 02:14:42 +01:00
|
|
|
|
|
|
|
alias Mobilizon.Federation.ActivityPub.Activity
|
2019-07-30 16:40:59 +02:00
|
|
|
|
|
|
|
@public "https://www.w3.org/ns/activitystreams#Public"
|
|
|
|
|
2024-01-04 13:35:02 +01:00
|
|
|
@spec public?(Activity.t() | map()) :: boolean()
|
|
|
|
def public?(%{data: %{"type" => "Tombstone"}}), do: false
|
|
|
|
def public?(%{data: data}), do: public?(data)
|
|
|
|
def public?(%Activity{data: data}), do: public?(data)
|
2019-12-03 11:29:51 +01:00
|
|
|
|
2024-01-04 13:35:02 +01:00
|
|
|
def public?(data) when is_map(data) do
|
2021-08-16 11:16:45 +02:00
|
|
|
@public in make_list(Map.get(data, "to", []))
|
2020-01-22 02:14:42 +01:00
|
|
|
end
|
2019-12-03 11:29:51 +01:00
|
|
|
|
2024-01-04 13:35:02 +01:00
|
|
|
def public?(%Comment{deleted_at: deleted_at}), do: !is_nil(deleted_at)
|
|
|
|
def public?(err), do: raise(ArgumentError, message: "Invalid argument #{inspect(err)}")
|
2020-10-25 19:17:31 +01:00
|
|
|
|
|
|
|
defp make_list(data) when is_list(data), do: data
|
|
|
|
defp make_list(data), do: [data]
|
2019-07-30 16:40:59 +02:00
|
|
|
end
|