2019-07-30 14:40:59 +00: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 01:14:42 +00:00
|
|
|
defmodule Mobilizon.Federation.ActivityPub.Visibility do
|
2019-07-30 14:40:59 +00:00
|
|
|
@moduledoc """
|
|
|
|
Utility functions related to content visibility
|
|
|
|
"""
|
2019-09-12 23:35:03 +00:00
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
alias Mobilizon.Discussions.Comment
|
2020-01-22 01:14:42 +00:00
|
|
|
|
|
|
|
alias Mobilizon.Federation.ActivityPub.Activity
|
2019-07-30 14:40:59 +00: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 10:29:51 +00:00
|
|
|
|
2020-01-22 01:14:42 +00:00
|
|
|
def is_public?(data) when is_map(data) do
|
2020-10-25 18:17:31 +00:00
|
|
|
@public in (make_list(Map.get(data, "to", [])) ++ make_list(Map.get(data, "cc", [])))
|
2020-01-22 01:14:42 +00:00
|
|
|
end
|
2019-12-03 10:29:51 +00:00
|
|
|
|
2019-11-15 17:36:47 +00:00
|
|
|
def is_public?(%Comment{deleted_at: deleted_at}), do: !is_nil(deleted_at)
|
2019-07-30 14:40:59 +00:00
|
|
|
def is_public?(err), do: raise(ArgumentError, message: "Invalid argument #{inspect(err)}")
|
2020-10-25 18:17:31 +00:00
|
|
|
|
|
|
|
defp make_list(data) when is_list(data), do: data
|
|
|
|
defp make_list(data), do: [data]
|
2019-07-30 14:40:59 +00:00
|
|
|
end
|