From f3f736afc4b4532ef71d5c6aba42945bd26a7699 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 25 Oct 2018 02:47:55 +0000 Subject: [PATCH 1/3] activity: add helper to fetch an activity's parent --- lib/pleroma/activity.ex | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index bed96861f..c065f3b6c 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -82,4 +82,10 @@ defmodule Pleroma.Activity do def normalize(obj) when is_map(obj), do: Activity.get_by_ap_id(obj["id"]) def normalize(ap_id) when is_binary(ap_id), do: Activity.get_by_ap_id(ap_id) def normalize(_), do: nil + + def get_in_reply_to_activity(%Activity{data: %{"object" => %{"inReplyTo" => ap_id}}}) do + get_create_activity_by_object_ap_id(ap_id) + end + + def get_in_reply_to_activity(_), do: nil end From fee43ae5e748368022cc5dc6393015ef64e0894b Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 25 Oct 2018 02:54:29 +0000 Subject: [PATCH 2/3] twitterapi: activity view: implement in_reply_to_screen_name using the new graph walking helper --- .../twitter_api/representers/activity_representer.ex | 10 ++++++++++ lib/pleroma/web/twitter_api/views/activity_view.ex | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index b21bbb205..04857001c 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -180,6 +180,15 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do attachments = (object["attachment"] || []) ++ video + reply_parent = Activity.get_in_reply_to_activity(activity) + + reply_user_nickname = + if reply_parent do + User.get_cached_by_ap_id(reply_parent.actor).nickname + else + nil + end + %{ "id" => activity.id, "uri" => activity.data["object"]["id"], @@ -190,6 +199,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do "is_post_verb" => true, "created_at" => created_at, "in_reply_to_status_id" => object["inReplyToStatusId"], + "in_reply_to_screen_name" => reply_user_nickname, "statusnet_conversation_id" => conversation_id, "attachments" => attachments |> ObjectRepresenter.enum_to_list(opts), "attentions" => attentions, diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index b9fd062d6..13fb04f95 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -236,6 +236,15 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do HTML.filter_tags(content, User.html_filter_policy(opts[:for])) |> Formatter.emojify(object["emoji"]) + reply_parent = Activity.get_in_reply_to_activity(activity) + + reply_user_nickname = + if reply_parent do + User.get_cached_by_ap_id(reply_parent.actor).nickname + else + nil + end + %{ "id" => activity.id, "uri" => activity.data["object"]["id"], @@ -246,6 +255,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do "is_post_verb" => true, "created_at" => created_at, "in_reply_to_status_id" => object["inReplyToStatusId"], + "in_reply_to_screen_name" => reply_user_nickname, "statusnet_conversation_id" => conversation_id, "attachments" => (object["attachment"] || []) |> ObjectRepresenter.enum_to_list(opts), "attentions" => attentions, From 9563f3766d45e6c95fe50e371bc0048d9f4a2452 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 25 Oct 2018 03:03:44 +0000 Subject: [PATCH 3/3] tests: update for new in_reply_to_screen_name field --- test/web/twitter_api/representers/activity_representer_test.exs | 1 + test/web/twitter_api/views/activity_view_test.exs | 1 + 2 files changed, 2 insertions(+) diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index 894d20049..ae6f62ed0 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -139,6 +139,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do "is_post_verb" => true, "created_at" => "Tue May 24 13:26:08 +0000 2016", "in_reply_to_status_id" => 213_123, + "in_reply_to_screen_name" => nil, "statusnet_conversation_id" => convo_object.id, "attachments" => [ ObjectRepresenter.to_map(object) diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index b9a8efdad..3ab87d6fa 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -36,6 +36,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do "favorited" => false, "id" => activity.id, "in_reply_to_status_id" => nil, + "in_reply_to_screen_name" => nil, "is_local" => true, "is_post_verb" => true, "possibly_sensitive" => false,