From 9c7da2ef4834729bd6bff21063bf81c7be5f1635 Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Sat, 26 May 2018 14:02:57 +0900 Subject: [PATCH 1/5] output repeats at ActivityPub outbox --- lib/pleroma/web/activity_pub/views/user_view.ex | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index ffd76b529..011ae18a3 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -98,9 +98,6 @@ def render("outbox.json", %{user: user, max_id: max_qid}) do info = User.user_info(user) params = %{ - "type" => ["Create", "Announce"], - "actor_id" => user.ap_id, - "whole_db" => true, "limit" => "10" } @@ -111,10 +108,8 @@ def render("outbox.json", %{user: user, max_id: max_qid}) do params end - activities = ActivityPub.fetch_public_activities(params) - min_id = Enum.at(activities, 0).id - - activities = Enum.reverse(activities) + activities = ActivityPub.fetch_public_activities(user, nil, params) + min_id = Enum.at(Enum.reverse(activities), 0).id max_id = Enum.at(activities, 0).id collection = From e90b734f1c41c13e08b7461f5bfb42745ea7ba08 Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Sat, 26 May 2018 14:10:12 +0900 Subject: [PATCH 2/5] debug --- lib/pleroma/web/activity_pub/views/user_view.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index 011ae18a3..719bd128b 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -108,7 +108,7 @@ def render("outbox.json", %{user: user, max_id: max_qid}) do params end - activities = ActivityPub.fetch_public_activities(user, nil, params) + activities = ActivityPub.fetch_user_activities(user, nil, params) min_id = Enum.at(Enum.reverse(activities), 0).id max_id = Enum.at(activities, 0).id From 9c2afb2e71d7ed072fbb43e2ef002e0d629ca877 Mon Sep 17 00:00:00 2001 From: hakabahitoyo Date: Sat, 21 Jul 2018 01:44:35 +0900 Subject: [PATCH 3/5] improve test --- .../activity_pub/activity_pub_controller_test.exs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index 25b47ee31..b9294efe1 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -50,6 +50,20 @@ test "it inserts an incoming activity into the database", %{conn: conn} do end end + describe "/users/:nickname/outbox" do + test "it returns a note action in a collection", %{conn: conn} do + note_activity = insert(:note_activity) + user = User.get_cached_by_ap_id(note_activity.data["actor"]) + + conn = + conn + |> put_req_header("Accept", "application/activity+json") + |> get("/users/#{user.nickname}/outbox") + + assert response(conn, 200) =~ note_activity.data["object"]["content"] + end + end + describe "/users/:nickname/followers" do test "it returns the followers in a collection", %{conn: conn} do user = insert(:user) From 908cefd84a6cf9bddd04ad9521be2ff5b7d8f379 Mon Sep 17 00:00:00 2001 From: hakabahitoyo Date: Sat, 21 Jul 2018 02:19:20 +0900 Subject: [PATCH 4/5] debug --- test/web/activity_pub/activity_pub_controller_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index b9294efe1..1daa5627c 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -57,7 +57,7 @@ test "it returns a note action in a collection", %{conn: conn} do conn = conn - |> put_req_header("Accept", "application/activity+json") + |> put_req_header("accept", "application/activity+json") |> get("/users/#{user.nickname}/outbox") assert response(conn, 200) =~ note_activity.data["object"]["content"] From 9c1b6f11c501756362342b5652769c9dfd12e77c Mon Sep 17 00:00:00 2001 From: hakabahitoyo Date: Sat, 21 Jul 2018 02:57:56 +0900 Subject: [PATCH 5/5] improve test --- test/support/factory.ex | 20 +++++++++++++++++++ .../activity_pub_controller_test.exs | 14 ++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/test/support/factory.ex b/test/support/factory.ex index b2e98c8d1..e9b4beb7d 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -65,6 +65,26 @@ def note_activity_factory do } end + def announce_activity_factory do + note_activity = insert(:note_activity) + user = insert(:user) + + data = %{ + "type" => "Announce", + "actor" => note_activity.actor, + "object" => note_activity.data["id"], + "to" => [user.follower_address, note_activity.data["actor"]], + "cc" => ["https://www.w3.org/ns/activitystreams#Public"], + "context" => note_activity.data["context"] + } + + %Pleroma.Activity{ + data: data, + actor: user.ap_id, + recipients: data["to"] + } + end + def like_activity_factory do note_activity = insert(:note_activity) user = insert(:user) diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index 1daa5627c..8a1c0d361 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -51,7 +51,7 @@ test "it inserts an incoming activity into the database", %{conn: conn} do end describe "/users/:nickname/outbox" do - test "it returns a note action in a collection", %{conn: conn} do + test "it returns a note activity in a collection", %{conn: conn} do note_activity = insert(:note_activity) user = User.get_cached_by_ap_id(note_activity.data["actor"]) @@ -62,6 +62,18 @@ test "it returns a note action in a collection", %{conn: conn} do assert response(conn, 200) =~ note_activity.data["object"]["content"] end + + test "it returns an announce activity in a collection", %{conn: conn} do + announce_activity = insert(:announce_activity) + user = User.get_cached_by_ap_id(announce_activity.data["actor"]) + + conn = + conn + |> put_req_header("accept", "application/activity+json") + |> get("/users/#{user.nickname}/outbox") + + assert response(conn, 200) =~ announce_activity.data["object"] + end end describe "/users/:nickname/followers" do