@emoji @finmoji_with_filenames
- def finmojifiy(text) do
+ def emojify(text) do
Enum.reduce(@emoji, text, fn ({emoji, file}, text) ->
String.replace(text, ":#{emoji}:", "<img height='32px' width='32px' alt='#{emoji}' title='#{emoji}' src='#{file}' />")
end)
end
+
+ def get_emoji(text) do
+ Enum.filter(@emoji, fn ({emoji, _}) -> String.contains?(text, ":#{emoji}:") end)
+ end
end
defmodule Pleroma.Web.OStatus.ActivityRepresenter do
alias Pleroma.{Activity, User, Object}
alias Pleroma.Web.OStatus.UserRepresenter
+ alias Pleroma.Formatter
require Logger
defp get_href(id) do
defp get_links(_activity), do: []
+ defp get_emoji_links(content) do
+ Enum.map(Formatter.get_emoji(content), fn({emoji, file}) ->
+ {:link, [name: to_charlist(emoji), rel: 'emoji', href: to_charlist("#{Pleroma.Web.Endpoint.static_url}#{file}")], []}
+ end)
+ end
+
def to_simple_form(activity, user, with_author \\ false)
def to_simple_form(%{data: %{"object" => %{"type" => "Note"}}} = activity, user, with_author) do
h = fn(str) -> [to_charlist(str)] end
categories = (activity.data["object"]["tag"] || [])
|> Enum.map(fn (tag) -> {:category, [term: to_charlist(tag)], []} end)
+ emoji_links = get_emoji_links(activity.data["object"]["content"] || "")
+
[
{:"activity:object-type", ['http://activitystrea.ms/schema/1.0/note']},
{:"activity:verb", ['http://activitystrea.ms/schema/1.0/post']},
{:updated, h.(updated_at)},
{:"ostatus:conversation", [ref: h.(activity.data["context"])], h.(activity.data["context"])},
{:link, [ref: h.(activity.data["context"]), rel: 'ostatus:conversation'], []},
- ] ++ get_links(activity) ++ categories ++ attachments ++ in_reply_to ++ author ++ mentions
+ ] ++ get_links(activity) ++ categories ++ attachments ++ in_reply_to ++ author ++ mentions ++ emoji_links
end
def to_simple_form(%{data: %{"type" => "Like"}} = activity, user, with_author) do
"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.finmojifiy,
+ "statusnet_html" => HtmlSanitizeEx.basic_html(content) |> Formatter.emojify,
"text" => HtmlSanitizeEx.strip_tags(content),
"is_local" => activity.local,
"is_post_verb" => true,
expected_result = "I love <img height='32px' width='32px' alt='moominmamma' title='moominmamma' src='/finmoji/128px/moominmamma-128.png' />"
- assert Formatter.finmojifiy(text) == expected_result
+ assert Formatter.emojify(text) == expected_result
+ end
+
+ test "it returns the emoji used in the text" do
+ text = "I love :moominmamma:"
+
+ assert Formatter.get_emoji(text) == [{"moominmamma", "/finmoji/128px/moominmamma-128.png"}]
end
end
<link type="text/html" href="#{note_activity.data["object"]["id"]}" rel="alternate" />
<category term="2hu"/>
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
+ <link name="moominmamma" rel="emoji" href="#{Pleroma.Web.Endpoint.static_url}/finmoji/128px/moominmamma-128.png" />
"""
tuple = ActivityRepresenter.to_simple_form(note_activity, user)
<category term="2hu"/>
<thr:in-reply-to ref="#{note.data["object"]["id"]}" href="someurl" />
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
+ <link name="moominmamma" rel="emoji" href="#{Pleroma.Web.Endpoint.static_url}/finmoji/128px/moominmamma-128.png" />
"""
tuple = ActivityRepresenter.to_simple_form(answer, user)