Apply incoming custom emoji.

This commit is contained in:
Roger Braun 2017-09-16 16:40:20 +02:00
commit 959e993c7d
3 changed files with 18 additions and 6 deletions

View file

@ -95,8 +95,14 @@ defmodule Pleroma.Formatter do
@emoji @finmoji_with_filenames
def emojify(text) do
Enum.reduce(@emoji, text, fn ({emoji, file}, text) ->
def emojify(text, additional \\ nil) do
all_emoji = if additional do
@emoji ++ Map.to_list(additional)
else
@emoji
end
Enum.reduce(all_emoji, text, fn ({emoji, file}, text) ->
String.replace(text, ":#{emoji}:", "<img height='32px' width='32px' alt='#{emoji}' title='#{emoji}' src='#{file}' />")
end)
end

View file

@ -135,11 +135,13 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
tags = activity.data["object"]["tag"] || []
possibly_sensitive = Enum.member?(tags, "nsfw")
html = HtmlSanitizeEx.basic_html(content) |> Formatter.emojify(object["emoji"])
%{
"id" => activity.id,
"uri" => activity.data["object"]["id"],
"user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
"statusnet_html" => HtmlSanitizeEx.basic_html(content) |> Formatter.emojify,
"statusnet_html" => html,
"text" => HtmlSanitizeEx.strip_tags(content),
"is_local" => activity.local,
"is_post_verb" => true,