forked from potsda.mn/mobilizon
Fix duplicate tags when editing an event with tags in description
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
eab36f40ec
commit
321a04babe
|
@ -15,7 +15,7 @@ defmodule Mobilizon.Service.ActivityPub.Converter.Utils do
|
||||||
def fetch_tags(tags) when is_list(tags) do
|
def fetch_tags(tags) when is_list(tags) do
|
||||||
Logger.debug("fetching tags")
|
Logger.debug("fetching tags")
|
||||||
|
|
||||||
Enum.reduce(tags, [], &fetch_tag/2)
|
tags |> Enum.flat_map(&fetch_tag/1) |> Enum.uniq() |> Enum.map(&existing_tag_or_data/1)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec fetch_mentions([map()]) :: [map()]
|
@spec fetch_mentions([map()]) :: [map()]
|
||||||
|
@ -64,23 +64,20 @@ defmodule Mobilizon.Service.ActivityPub.Converter.Utils do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp fetch_tag(tag, acc) when is_map(tag) do
|
defp fetch_tag(tag) when is_map(tag) do
|
||||||
case tag["type"] do
|
case tag["type"] do
|
||||||
"Hashtag" ->
|
"Hashtag" ->
|
||||||
acc ++ [existing_tag_or_data(tag["name"])]
|
[tag_without_hash(tag["name"])]
|
||||||
|
|
||||||
_err ->
|
_err ->
|
||||||
acc
|
[]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp fetch_tag(tag, acc) when is_bitstring(tag) do
|
defp fetch_tag(tag) when is_bitstring(tag), do: [tag_without_hash(tag)]
|
||||||
acc ++ [existing_tag_or_data(tag)]
|
|
||||||
end
|
|
||||||
|
|
||||||
defp existing_tag_or_data("#" <> tag_title) do
|
defp tag_without_hash("#" <> tag_title), do: tag_title
|
||||||
existing_tag_or_data(tag_title)
|
defp tag_without_hash(tag_title), do: tag_title
|
||||||
end
|
|
||||||
|
|
||||||
defp existing_tag_or_data(tag_title) do
|
defp existing_tag_or_data(tag_title) do
|
||||||
case Events.get_tag_by_title(tag_title) do
|
case Events.get_tag_by_title(tag_title) do
|
||||||
|
|
Loading…
Reference in a new issue