formatter.ex: Add get_emoji_map/1

This commit is contained in:
Haelwenn (lanodan) Monnier 2019-02-12 14:59:34 +01:00
commit 2f76a40d02
No known key found for this signature in database
GPG key ID: D5B7A8E43C997DEE
7 changed files with 72 additions and 10 deletions

View file

@ -128,12 +128,23 @@ defmodule Pleroma.Formatter do
def demojify(text, nil), do: text
@doc "Outputs a list of the emoji-shortcodes in a text"
def get_emoji(text) when is_binary(text) do
Enum.filter(Emoji.get_all(), fn {emoji, _, _} -> String.contains?(text, ":#{emoji}:") end)
end
def get_emoji(_), do: []
@doc "Outputs a list of the emoji-Maps in a text"
def get_emoji_map(text) when is_binary(text) do
get_emoji(text)
|> Enum.reduce(%{}, fn {name, file, _group}, acc ->
Map.put(acc, name, "#{Pleroma.Web.Endpoint.static_url()}#{file}")
end)
end
def get_emoji_map(_), do: []
def html_escape({text, mentions, hashtags}, type) do
{html_escape(text, type), mentions, hashtags}
end