From 52493467ac314ec58ed6123d3581428a82ec170c Mon Sep 17 00:00:00 2001 From: scarlett Date: Sun, 6 Jan 2019 10:16:40 +0000 Subject: [PATCH] Twitter API: Add a summary_html field. The intention here is to allow proper subject copying when it contains emoji, obviously this will require minor frontend changes, though. --- .../web/twitter_api/representers/activity_representer.ex | 5 ++++- lib/pleroma/web/twitter_api/views/activity_view.ex | 5 ++++- .../twitter_api/representers/activity_representer_test.exs | 3 ++- test/web/twitter_api/views/activity_view_test.exs | 7 ++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index 245cd52fd..47154829d 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -181,6 +181,8 @@ def to_map( reply_user = reply_parent && User.get_cached_by_ap_id(reply_parent.actor) + summary = HTML.strip_tags(object["summary"]) + %{ "id" => activity.id, "uri" => activity.data["object"]["id"], @@ -207,7 +209,8 @@ def to_map( "activity_type" => "post", "possibly_sensitive" => possibly_sensitive, "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object), - "summary" => HTML.strip_tags(object["summary"]) |> Formatter.emojify(object["emoji"]) + "summary" => summary, + "summary_html" => summary |> Formatter.emojify(object["emoji"]) } end diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index ad0cc76ed..61c617e87 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -263,6 +263,8 @@ def render( reply_user = reply_parent && User.get_cached_by_ap_id(reply_parent.actor) + summary = HTML.strip_tags(summary) + %{ "id" => activity.id, "uri" => activity.data["object"]["id"], @@ -289,7 +291,8 @@ def render( "activity_type" => "post", "possibly_sensitive" => possibly_sensitive, "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object), - "summary" => HTML.strip_tags(summary) |> Formatter.emojify(object["emoji"]) + "summary" => summary, + "summary_html" => summary |> Formatter.emojify(object["emoji"]) } end diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index 2ac32aeb2..ab3e04985 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -163,7 +163,8 @@ test "an activity" do "possibly_sensitive" => true, "uri" => activity.data["object"]["id"], "visibility" => "direct", - "summary" => "2hu" + "summary" => "2hu", + "summary_html" => "2hu" } assert ActivityRepresenter.to_map(activity, %{ diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 05780a54a..a03f48b61 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -50,10 +50,13 @@ test "a create activity with a summary containing emoji" do result = ActivityView.render("activity.json", activity: activity) - expected = + expected = ":woollysocks: meow" + + expected_html = "\"woollysocks\" meow" assert result["summary"] == expected + assert result["summary_html"] == expected_html end test "a create activity with a summary containing invalid HTML" do @@ -68,6 +71,7 @@ test "a create activity with a summary containing invalid HTML" do expected = "meow" assert result["summary"] == expected + assert result["summary_html"] == expected end test "a create activity with a note" do @@ -103,6 +107,7 @@ test "a create activity with a note" do "repeated" => false, "statusnet_conversation_id" => convo_id, "summary" => "", + "summary_html" => "", "statusnet_html" => "Hey @shp!", "tags" => [],