fix(activitypub): also handle as:Public and Public values for public addressing

Closes #1413

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2024-02-08 17:51:14 +01:00
parent 67314928e0
commit 4dc2f489e7
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
3 changed files with 16 additions and 6 deletions

View file

@ -32,7 +32,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
maybe_fetch_actor_and_attributed_to_id: 1,
process_pictures: 2,
get_address: 1,
fetch_actor: 1
fetch_actor: 1,
visibility_public?: 1
]
import Mobilizon.Service.Metadata.Utils,
@ -226,7 +227,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
defp get_metdata(_), do: []
defp get_visibility(object), do: if(@ap_public in object["to"], do: :public, else: :unlisted)
defp get_visibility(object),
do: if(visibility_public?(object["to"]), do: :public, else: :unlisted)
@spec date_to_string(DateTime.t() | nil) :: String.t()
defp date_to_string(nil), do: nil

View file

@ -15,7 +15,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Post do
import Mobilizon.Federation.ActivityStream.Converter.Utils,
only: [
process_pictures: 2
process_pictures: 2,
visibility_public?: 1
]
import Mobilizon.Service.Guards, only: [is_valid_string: 1]
@ -134,14 +135,12 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Post do
)
end
@ap_public "https://www.w3.org/ns/activitystreams#Public"
defp get_visibility(%{"to" => to}, %Actor{
followers_url: followers_url,
members_url: members_url
}) do
cond do
@ap_public in to -> :public
visibility_public?(to) -> :public
followers_url in to -> :unlisted
members_url in to -> :private
end

View file

@ -335,4 +335,13 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Utils do
nil
end
end
@ap_public "https://www.w3.org/ns/activitystreams#Public"
@spec visibility_public?(String.t() | list(String.t())) :: boolean()
def visibility_public?(to) when is_binary(to), do: visibility_public?([to])
def visibility_public?(to) when is_list(to) do
!MapSet.disjoint?(MapSet.new(to), MapSet.new([@ap_public, "as:Public", "Public"]))
end
end