Don't go through all available emoji.

object carry their emoji information.
This commit is contained in:
lain 2018-03-28 09:56:32 +02:00
parent e30752bc79
commit df8fc72491
3 changed files with 8 additions and 10 deletions

View File

@ -110,14 +110,10 @@ def parse_mentions(text) do
@emoji @finmoji_with_filenames ++ @emoji_from_file @emoji @finmoji_with_filenames ++ @emoji_from_file
def emojify(text, additional \\ nil) do def emojify(text, emoji \\ @emoji)
all_emoji = if additional do def emojify(text, nil), do: text
Map.to_list(additional) ++ @emoji def emojify(text, emoji) do
else Enum.reduce(emoji, text, fn ({emoji, file}, text) ->
@emoji
end
Enum.reduce(all_emoji, text, fn ({emoji, file}, text) ->
emoji = HtmlSanitizeEx.strip_tags(emoji) emoji = HtmlSanitizeEx.strip_tags(emoji)
file = HtmlSanitizeEx.strip_tags(file) file = HtmlSanitizeEx.strip_tags(file)
String.replace(text, ":#{emoji}:", "<img height='32px' width='32px' alt='#{emoji}' title='#{emoji}' src='#{MediaProxy.url(file)}' />") String.replace(text, ":#{emoji}:", "<img height='32px' width='32px' alt='#{emoji}' title='#{emoji}' src='#{MediaProxy.url(file)}' />")

View File

@ -145,7 +145,8 @@ def to_map(%Activity{data: %{"object" => %{"content" => content} = object}} = ac
content content
end end
html = HtmlSanitizeEx.basic_html(content) |> Formatter.emojify(object["emoji"]) html = HtmlSanitizeEx.basic_html(content)
|> Formatter.emojify(object["emoji"])
%{ %{
"id" => activity.id, "id" => activity.id,

View File

@ -37,7 +37,8 @@ def render("activity.json", %{activity: %{data: %{"type" => "Create", "object" =
content content
end end
html = HtmlSanitizeEx.basic_html(content) |> Formatter.emojify(object["emoji"]) html = HtmlSanitizeEx.basic_html(content)
|> Formatter.emojify(object["emoji"])
%{ %{
"id" => activity.id, "id" => activity.id,