Twitter API: Add a summary_html field.
authorscarlett <nia@netbsd.org>
Sun, 6 Jan 2019 10:16:40 +0000 (10:16 +0000)
committerscarlett <nia@netbsd.org>
Sun, 6 Jan 2019 10:19:00 +0000 (10:19 +0000)
The intention here is to allow proper subject copying when it contains
emoji, obviously this will require minor frontend changes, though.

lib/pleroma/web/twitter_api/representers/activity_representer.ex
lib/pleroma/web/twitter_api/views/activity_view.ex
test/web/twitter_api/representers/activity_representer_test.exs
test/web/twitter_api/views/activity_view_test.exs

index 245cd52fd60eddaf7de309c7d95fd6bf10a61774..47154829dfede3a57e6039ba68c07a111d1ffc2f 100644 (file)
@@ -181,6 +181,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
 
     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 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
       "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
 
index ad0cc76edf72adac00a899c19a7f6b052fec5e0d..61c617e87c987d8c541aa6d8dd0b8f7dba51df14 100644 (file)
@@ -263,6 +263,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
 
     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 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
       "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
 
index 2ac32aeb2243a8b1d9cb043ad29cdd841f666356..ab3e04985199c943ff89389d4b2d6e0c10b7f24f 100644 (file)
@@ -163,7 +163,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
       "possibly_sensitive" => true,
       "uri" => activity.data["object"]["id"],
       "visibility" => "direct",
-      "summary" => "2hu"
+      "summary" => "2hu",
+      "summary_html" => "2hu"
     }
 
     assert ActivityRepresenter.to_map(activity, %{
index 05780a54ada9e4d86793e6e76d01de7843e31948..a03f48b61e608438c6f39dd2b1b22087627cf05e 100644 (file)
@@ -50,10 +50,13 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
 
     result = ActivityView.render("activity.json", activity: activity)
 
-    expected =
+    expected = ":woollysocks: meow"
+
+    expected_html =
       "<img height=\"32px\" width=\"32px\" alt=\"woollysocks\" title=\"woollysocks\" src=\"http://localhost:4001/finmoji/128px/woollysocks-128.png\" /> 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 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest 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 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
       "repeated" => false,
       "statusnet_conversation_id" => convo_id,
       "summary" => "",
+      "summary_html" => "",
       "statusnet_html" =>
         "Hey <span><a data-user=\"#{other_user.id}\" href=\"#{other_user.ap_id}\">@<span>shp</span></a></span>!",
       "tags" => [],