From 1b480e351405a4f987e0ba21bfe845cef7ff36de Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 25 Oct 2018 04:01:59 +0000 Subject: [PATCH 1/3] user: add helper for fetching profile url (which may be different than ap id) --- lib/pleroma/user.ex | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index e97224731..0c9fa559a 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -42,6 +42,10 @@ def banner_url(user) do end end + def profile_url(%User{info: %{"source_data" => %{"url" => url}}}), do: url + def profile_url(%User{ap_id: ap_id}), do: ap_id + def profile_url(_), do: nil + def ap_id(%User{nickname: nickname}) do "#{Web.base_url()}/users/#{nickname}" end From 1ed25c963a69d0f4cabcb7adfed0739af82d1f32 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 25 Oct 2018 04:04:04 +0000 Subject: [PATCH 2/3] twitterapi: activity view: add the other in_reply_to fields --- .../twitter_api/representers/activity_representer.ex | 12 +++++------- lib/pleroma/web/twitter_api/views/activity_view.ex | 12 +++++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index 04857001c..fbd33f07e 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -182,12 +182,7 @@ def to_map( 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 + reply_user = reply_parent && User.get_cached_by_ap_id(reply_parent.actor) %{ "id" => activity.id, @@ -199,7 +194,10 @@ def to_map( "is_post_verb" => true, "created_at" => created_at, "in_reply_to_status_id" => object["inReplyToStatusId"], - "in_reply_to_screen_name" => reply_user_nickname, + "in_reply_to_screen_name" => reply_user && reply_user.nickname, + "in_reply_to_profileurl" => User.profile_url(reply_user), + "in_reply_to_ostatus_uri" => reply_user && reply_user.ap_id, + "in_reply_to_user_id" => reply_user && reply_user.id, "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 13fb04f95..fb97f199b 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -238,12 +238,7 @@ def render( 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 + reply_user = reply_parent && User.get_cached_by_ap_id(reply_parent.actor) %{ "id" => activity.id, @@ -255,7 +250,10 @@ def render( "is_post_verb" => true, "created_at" => created_at, "in_reply_to_status_id" => object["inReplyToStatusId"], - "in_reply_to_screen_name" => reply_user_nickname, + "in_reply_to_screen_name" => reply_user && reply_user.nickname, + "in_reply_to_profileurl" => User.profile_url(reply_user), + "in_reply_to_ostatus_uri" => reply_user && reply_user.ap_id, + "in_reply_to_user_id" => reply_user && reply_user.id, "statusnet_conversation_id" => conversation_id, "attachments" => (object["attachment"] || []) |> ObjectRepresenter.enum_to_list(opts), "attentions" => attentions, From 6cfba7db8de1cdb409243885724101500fa21e6d Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 25 Oct 2018 04:06:42 +0000 Subject: [PATCH 3/3] tests: twitterapi: add additional fields --- .../web/twitter_api/representers/activity_representer_test.exs | 3 +++ test/web/twitter_api/views/activity_view_test.exs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index ae6f62ed0..291fd5237 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -140,6 +140,9 @@ test "an activity" do "created_at" => "Tue May 24 13:26:08 +0000 2016", "in_reply_to_status_id" => 213_123, "in_reply_to_screen_name" => nil, + "in_reply_to_user_id" => nil, + "in_reply_to_profileurl" => nil, + "in_reply_to_ostatus_uri" => 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 3ab87d6fa..5cef06f88 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -37,6 +37,9 @@ test "a create activity with a note" do "id" => activity.id, "in_reply_to_status_id" => nil, "in_reply_to_screen_name" => nil, + "in_reply_to_user_id" => nil, + "in_reply_to_profileurl" => nil, + "in_reply_to_ostatus_uri" => nil, "is_local" => true, "is_post_verb" => true, "possibly_sensitive" => false,