From df8fc7249103fc1fdb574463201f02f4c99f9bec Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 28 Mar 2018 09:56:32 +0200 Subject: [PATCH] Don't go through all available emoji. object carry their emoji information. --- lib/pleroma/formatter.ex | 12 ++++-------- .../twitter_api/representers/activity_representer.ex | 3 ++- lib/pleroma/web/twitter_api/views/activity_view.ex | 3 ++- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 4afc73bf4..66ca92f27 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -110,14 +110,10 @@ def parse_mentions(text) do @emoji @finmoji_with_filenames ++ @emoji_from_file - def emojify(text, additional \\ nil) do - all_emoji = if additional do - Map.to_list(additional) ++ @emoji - else - @emoji - end - - Enum.reduce(all_emoji, text, fn ({emoji, file}, text) -> + def emojify(text, emoji \\ @emoji) + def emojify(text, nil), do: text + def emojify(text, emoji) do + Enum.reduce(emoji, text, fn ({emoji, file}, text) -> emoji = HtmlSanitizeEx.strip_tags(emoji) file = HtmlSanitizeEx.strip_tags(file) String.replace(text, ":#{emoji}:", "#{emoji}") diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index 5199cef8e..73ae3422b 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -145,7 +145,8 @@ def to_map(%Activity{data: %{"object" => %{"content" => content} = object}} = ac content end - html = HtmlSanitizeEx.basic_html(content) |> Formatter.emojify(object["emoji"]) + html = HtmlSanitizeEx.basic_html(content) + |> Formatter.emojify(object["emoji"]) %{ "id" => activity.id, diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 76b8cb14b..ae5be60ce 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -37,7 +37,8 @@ def render("activity.json", %{activity: %{data: %{"type" => "Create", "object" = content end - html = HtmlSanitizeEx.basic_html(content) |> Formatter.emojify(object["emoji"]) + html = HtmlSanitizeEx.basic_html(content) + |> Formatter.emojify(object["emoji"]) %{ "id" => activity.id,