Refactor Mobilizon.Federation.ActivityPub.Types.Events tags handling

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-04-21 17:31:47 +02:00
parent d05eb96ac6
commit 279badb2bf
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773

View File

@ -268,14 +268,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Events do
description: description, description: description,
mentions: mentions, mentions: mentions,
# Exclude tags with length > 40 # Exclude tags with length > 40
tags: tags: Enum.filter(tags, &exclude_too_long_tags/1)
Enum.filter(tags, fn tag ->
case tag do
# For some reason transmogrifier gives us this
%{title: tag} -> String.length(tag) < 40
tag -> String.length(tag) < 40
end
end)
}) })
else else
args args
@ -287,13 +280,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Events do
args, args,
:tags, :tags,
[], [],
&Enum.uniq_by(&1, fn tag -> &Enum.uniq_by(&1, fn tag -> tag |> tag_to_string() |> String.downcase() end)
case tag do
# For some reason transmogrifier gives us this
%{title: tag} -> String.downcase(tag)
tag -> String.downcase(tag)
end
end)
) )
# Check that we can only allow anonymous participation if our instance allows it # Check that we can only allow anonymous participation if our instance allows it
@ -315,4 +302,16 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Events do
|> Map.update(:tags, [], &ConverterUtils.fetch_tags/1) |> Map.update(:tags, [], &ConverterUtils.fetch_tags/1)
|> Map.update(:contacts, [], &ConverterUtils.fetch_actors/1) |> Map.update(:contacts, [], &ConverterUtils.fetch_actors/1)
end end
@spec exclude_too_long_tags(%{title: String.t()} | String.t()) :: boolean()
defp exclude_too_long_tags(tag) do
tag
|> tag_to_string()
|> String.length()
|> Kernel.<(40)
end
@spec tag_to_string(%{title: String.t()} | String.t()) :: String.t()
defp tag_to_string(%{title: tag}), do: tag
defp tag_to_string(tag), do: tag
end end