forked from potsda.mn/mobilizon
Refactor Mobilizon.Federation.ActivityPub.Types.Events tags handling
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
d05eb96ac6
commit
279badb2bf
|
@ -268,14 +268,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Events do
|
|||
description: description,
|
||||
mentions: mentions,
|
||||
# Exclude tags with length > 40
|
||||
tags:
|
||||
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)
|
||||
tags: Enum.filter(tags, &exclude_too_long_tags/1)
|
||||
})
|
||||
else
|
||||
args
|
||||
|
@ -287,13 +280,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Events do
|
|||
args,
|
||||
:tags,
|
||||
[],
|
||||
&Enum.uniq_by(&1, fn tag ->
|
||||
case tag do
|
||||
# For some reason transmogrifier gives us this
|
||||
%{title: tag} -> String.downcase(tag)
|
||||
tag -> String.downcase(tag)
|
||||
end
|
||||
end)
|
||||
&Enum.uniq_by(&1, fn tag -> tag |> tag_to_string() |> String.downcase() end)
|
||||
)
|
||||
|
||||
# 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(:contacts, [], &ConverterUtils.fetch_actors/1)
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue