[Pleroma.Web.ActivityPub.Transmogrifier]: fix emoji in tag when it’s not in a array [kroeg]
Also simplified the code for name trimming. And not copying the Map.merge part as it looks buggy. See: https://queer.hacktivis.me/objects/a9f21ebc-9a12-4a6c-89d5-3d46955c6ee8
This commit is contained in:
parent
f8a0cb9c0b
commit
28e8a8ab36
|
@ -164,21 +164,13 @@ def fix_attachments(object) do
|
||||||
object
|
object
|
||||||
end
|
end
|
||||||
|
|
||||||
def fix_emoji(object) do
|
def fix_emoji(%{"tag" => tags} = object) when is_list(tags) do
|
||||||
tags = object["tag"] || []
|
|
||||||
emoji = tags |> Enum.filter(fn data -> data["type"] == "Emoji" and data["icon"] end)
|
emoji = tags |> Enum.filter(fn data -> data["type"] == "Emoji" and data["icon"] end)
|
||||||
|
|
||||||
emoji =
|
emoji =
|
||||||
emoji
|
emoji
|
||||||
|> Enum.reduce(%{}, fn data, mapping ->
|
|> Enum.reduce(%{}, fn data, mapping ->
|
||||||
name = data["name"]
|
name = String.trim(data["name"], ":")
|
||||||
|
|
||||||
name =
|
|
||||||
if String.starts_with?(name, ":") do
|
|
||||||
name |> String.slice(1..-2)
|
|
||||||
else
|
|
||||||
name
|
|
||||||
end
|
|
||||||
|
|
||||||
mapping |> Map.put(name, data["icon"]["url"])
|
mapping |> Map.put(name, data["icon"]["url"])
|
||||||
end)
|
end)
|
||||||
|
@ -190,6 +182,18 @@ def fix_emoji(object) do
|
||||||
|> Map.put("emoji", emoji)
|
|> Map.put("emoji", emoji)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fix_emoji(%{"tag" => %{"type" => "Emoji"} = tag} = object) do
|
||||||
|
name = String.trim(tag["name"], ":")
|
||||||
|
emoji = %{name => tag["icon"]["url"]}
|
||||||
|
|
||||||
|
object
|
||||||
|
|> Map.put("emoji", emoji)
|
||||||
|
end
|
||||||
|
|
||||||
|
def fix_emoji(object) do
|
||||||
|
object
|
||||||
|
end
|
||||||
|
|
||||||
def fix_tag(object) do
|
def fix_tag(object) do
|
||||||
tags =
|
tags =
|
||||||
(object["tag"] || [])
|
(object["tag"] || [])
|
||||||
|
|
Loading…
Reference in New Issue