From 28e8a8ab36ea0bdb8f8412cb6192b2e728a96b90 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 21 Sep 2018 14:36:29 +0200 Subject: [PATCH] =?utf8?q?[Pleroma.Web.ActivityPub.Transmogrifier]:=20fix?= =?utf8?q?=20emoji=20in=20tag=20when=20it=E2=80=99s=20not=20in=20a=20array?= =?utf8?q?=20[kroeg]?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- .../web/activity_pub/transmogrifier.ex | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 8677bc208..a37c8477f 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -164,21 +164,13 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do object end - def fix_emoji(object) do - tags = object["tag"] || [] + def fix_emoji(%{"tag" => tags} = object) when is_list(tags) do emoji = tags |> Enum.filter(fn data -> data["type"] == "Emoji" and data["icon"] end) emoji = emoji |> Enum.reduce(%{}, fn data, mapping -> - name = data["name"] - - name = - if String.starts_with?(name, ":") do - name |> String.slice(1..-2) - else - name - end + name = String.trim(data["name"], ":") mapping |> Map.put(name, data["icon"]["url"]) end) @@ -190,6 +182,18 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do |> Map.put("emoji", emoji) 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 tags = (object["tag"] || []) -- 2.45.2