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.
This commit is contained in:
scarlett 2019-01-06 10:16:40 +00:00
parent b0e8e521fb
commit 52493467ac
4 changed files with 16 additions and 4 deletions

View file

@ -181,6 +181,8 @@ def to_map(
reply_user = reply_parent && User.get_cached_by_ap_id(reply_parent.actor) reply_user = reply_parent && User.get_cached_by_ap_id(reply_parent.actor)
summary = HTML.strip_tags(object["summary"])
%{ %{
"id" => activity.id, "id" => activity.id,
"uri" => activity.data["object"]["id"], "uri" => activity.data["object"]["id"],
@ -207,7 +209,8 @@ def to_map(
"activity_type" => "post", "activity_type" => "post",
"possibly_sensitive" => possibly_sensitive, "possibly_sensitive" => possibly_sensitive,
"visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object), "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 end

View file

@ -263,6 +263,8 @@ def render(
reply_user = reply_parent && User.get_cached_by_ap_id(reply_parent.actor) reply_user = reply_parent && User.get_cached_by_ap_id(reply_parent.actor)
summary = HTML.strip_tags(summary)
%{ %{
"id" => activity.id, "id" => activity.id,
"uri" => activity.data["object"]["id"], "uri" => activity.data["object"]["id"],
@ -289,7 +291,8 @@ def render(
"activity_type" => "post", "activity_type" => "post",
"possibly_sensitive" => possibly_sensitive, "possibly_sensitive" => possibly_sensitive,
"visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object), "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 end

View file

@ -163,7 +163,8 @@ test "an activity" do
"possibly_sensitive" => true, "possibly_sensitive" => true,
"uri" => activity.data["object"]["id"], "uri" => activity.data["object"]["id"],
"visibility" => "direct", "visibility" => "direct",
"summary" => "2hu" "summary" => "2hu",
"summary_html" => "2hu"
} }
assert ActivityRepresenter.to_map(activity, %{ assert ActivityRepresenter.to_map(activity, %{

View file

@ -50,10 +50,13 @@ test "a create activity with a summary containing emoji" do
result = ActivityView.render("activity.json", activity: activity) 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" "<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"] == expected
assert result["summary_html"] == expected_html
end end
test "a create activity with a summary containing invalid HTML" do 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" expected = "meow"
assert result["summary"] == expected assert result["summary"] == expected
assert result["summary_html"] == expected
end end
test "a create activity with a note" do test "a create activity with a note" do
@ -103,6 +107,7 @@ test "a create activity with a note" do
"repeated" => false, "repeated" => false,
"statusnet_conversation_id" => convo_id, "statusnet_conversation_id" => convo_id,
"summary" => "", "summary" => "",
"summary_html" => "",
"statusnet_html" => "statusnet_html" =>
"Hey <span><a data-user=\"#{other_user.id}\" href=\"#{other_user.ap_id}\">@<span>shp</span></a></span>!", "Hey <span><a data-user=\"#{other_user.id}\" href=\"#{other_user.ap_id}\">@<span>shp</span></a></span>!",
"tags" => [], "tags" => [],