Federate emoji out.
This commit is contained in:
parent
79aeb219d8
commit
884006a9e9
6 changed files with 26 additions and 5 deletions
|
|
@ -95,9 +95,13 @@ defmodule Pleroma.Formatter do
|
|||
|
||||
@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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
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
|
||||
|
|
@ -55,6 +56,12 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter 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
|
||||
|
|
@ -74,6 +81,8 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
|
|||
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']},
|
||||
|
|
@ -84,7 +93,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
|
|||
{: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
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter 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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue