From 4dc2f489e79d4f7d64ba3d5c2588d5d6ec0bc99c Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 8 Feb 2024 17:51:14 +0100 Subject: [PATCH] fix(activitypub): also handle as:Public and Public values for public addressing Closes #1413 Signed-off-by: Thomas Citharel --- lib/federation/activity_stream/converter/event.ex | 6 ++++-- lib/federation/activity_stream/converter/post.ex | 7 +++---- lib/federation/activity_stream/converter/utils.ex | 9 +++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/federation/activity_stream/converter/event.ex b/lib/federation/activity_stream/converter/event.ex index bed443b36..bff0dca63 100644 --- a/lib/federation/activity_stream/converter/event.ex +++ b/lib/federation/activity_stream/converter/event.ex @@ -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 diff --git a/lib/federation/activity_stream/converter/post.ex b/lib/federation/activity_stream/converter/post.ex index 40f3eab43..e7231dd8d 100644 --- a/lib/federation/activity_stream/converter/post.ex +++ b/lib/federation/activity_stream/converter/post.ex @@ -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 diff --git a/lib/federation/activity_stream/converter/utils.ex b/lib/federation/activity_stream/converter/utils.ex index 760fdc28c..0af6e976f 100644 --- a/lib/federation/activity_stream/converter/utils.ex +++ b/lib/federation/activity_stream/converter/utils.ex @@ -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