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:
parent
67314928e0
commit
4dc2f489e7
|
@ -32,7 +32,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
|
||||||
maybe_fetch_actor_and_attributed_to_id: 1,
|
maybe_fetch_actor_and_attributed_to_id: 1,
|
||||||
process_pictures: 2,
|
process_pictures: 2,
|
||||||
get_address: 1,
|
get_address: 1,
|
||||||
fetch_actor: 1
|
fetch_actor: 1,
|
||||||
|
visibility_public?: 1
|
||||||
]
|
]
|
||||||
|
|
||||||
import Mobilizon.Service.Metadata.Utils,
|
import Mobilizon.Service.Metadata.Utils,
|
||||||
|
@ -226,7 +227,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
|
||||||
|
|
||||||
defp get_metdata(_), 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()
|
@spec date_to_string(DateTime.t() | nil) :: String.t()
|
||||||
defp date_to_string(nil), do: nil
|
defp date_to_string(nil), do: nil
|
||||||
|
|
|
@ -15,7 +15,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Post do
|
||||||
|
|
||||||
import Mobilizon.Federation.ActivityStream.Converter.Utils,
|
import Mobilizon.Federation.ActivityStream.Converter.Utils,
|
||||||
only: [
|
only: [
|
||||||
process_pictures: 2
|
process_pictures: 2,
|
||||||
|
visibility_public?: 1
|
||||||
]
|
]
|
||||||
|
|
||||||
import Mobilizon.Service.Guards, only: [is_valid_string: 1]
|
import Mobilizon.Service.Guards, only: [is_valid_string: 1]
|
||||||
|
@ -134,14 +135,12 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Post do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ap_public "https://www.w3.org/ns/activitystreams#Public"
|
|
||||||
|
|
||||||
defp get_visibility(%{"to" => to}, %Actor{
|
defp get_visibility(%{"to" => to}, %Actor{
|
||||||
followers_url: followers_url,
|
followers_url: followers_url,
|
||||||
members_url: members_url
|
members_url: members_url
|
||||||
}) do
|
}) do
|
||||||
cond do
|
cond do
|
||||||
@ap_public in to -> :public
|
visibility_public?(to) -> :public
|
||||||
followers_url in to -> :unlisted
|
followers_url in to -> :unlisted
|
||||||
members_url in to -> :private
|
members_url in to -> :private
|
||||||
end
|
end
|
||||||
|
|
|
@ -335,4 +335,13 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Utils do
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue