From 16b1fcd2719b744c81851e778df2519dc0131010 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sat, 16 Sep 2017 16:27:48 +0200 Subject: [PATCH] Handle incoming emoji. --- lib/pleroma/web/ostatus/handlers/note_handler.ex | 12 ++++++++++++ test/fixtures/incoming_note_activity.xml | 2 ++ test/web/ostatus/ostatus_test.exs | 1 + 3 files changed, 15 insertions(+) diff --git a/lib/pleroma/web/ostatus/handlers/note_handler.ex b/lib/pleroma/web/ostatus/handlers/note_handler.ex index 0b06f8f02..dda5c7d5e 100644 --- a/lib/pleroma/web/ostatus/handlers/note_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/note_handler.ex @@ -52,6 +52,17 @@ defmodule Pleroma.Web.OStatus.NoteHandler do |> Enum.filter(&(&1)) end + def get_emoji(entry) do + try do + :xmerl_xpath.string('//link[@rel="emoji"]', entry) + |> Enum.reduce(%{}, fn(emoji, acc) -> + Map.put(acc, XML.string_from_xpath("@name", emoji), XML.string_from_xpath("@href", emoji)) + end) + rescue + _e -> nil + end + end + def make_to_list(actor, mentions) do [ actor.follower_address @@ -95,6 +106,7 @@ defmodule Pleroma.Web.OStatus.NoteHandler do note <- CommonAPI.Utils.make_note_data(actor.ap_id, to, context, content_html, attachments, inReplyToActivity, []), note <- note |> Map.put("id", id) |> Map.put("tag", tags), note <- note |> Map.put("published", date), + note <- note |> Map.put("emoji", get_emoji(entry)), note <- add_external_url(note, entry), # TODO: Handle this case in make_note_data note <- (if inReplyTo && !inReplyToActivity, do: note |> Map.put("inReplyTo", inReplyTo), else: note) diff --git a/test/fixtures/incoming_note_activity.xml b/test/fixtures/incoming_note_activity.xml index e54b25e39..21eda2d30 100644 --- a/test/fixtures/incoming_note_activity.xml +++ b/test/fixtures/incoming_note_activity.xml @@ -4,6 +4,8 @@ New note by lambda @<a href="http://pleroma.example.org:4000/users/lain3" class="h-card mention">lain3</a> + + http://activitystrea.ms/schema/1.0/post 2017-04-23T14:51:03+00:00 diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs index ee2b79ffa..95038b73c 100644 --- a/test/web/ostatus/ostatus_test.exs +++ b/test/web/ostatus/ostatus_test.exs @@ -24,6 +24,7 @@ defmodule Pleroma.Web.OStatusTest do assert activity.data["object"]["published"] == "2017-04-23T14:51:03+00:00" assert activity.data["context"] == "tag:gs.example.org:4040,2017-04-23:objectType=thread:nonce=f09e22f58abd5c7b" assert "http://pleroma.example.org:4000/users/lain3" in activity.data["to"] + assert activity.data["object"]["emoji"] == %{ "marko" => "marko.png", "reimu" => "reimu.png" } assert activity.local == false end -- 2.45.2