From 7c722c08f5fa44fc5d1baf0eb0fabb32942988a2 Mon Sep 17 00:00:00 2001 From: KZ Date: Fri, 22 Feb 2019 04:37:48 +0000 Subject: [PATCH] Fix: Fixing an outbox related bug when local user activity is empty --- .../web/activity_pub/views/user_view.ex | 24 +++++++++++++------ .../activity_pub_controller_test.exs | 12 ++++++++++ 2 files changed, 29 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 c8e154989..415cbd47a 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -188,14 +188,24 @@ def render("outbox.json", %{user: user, max_id: max_qid}) do end activities = ActivityPub.fetch_user_activities(user, nil, params) - min_id = Enum.at(Enum.reverse(activities), 0).id - max_id = Enum.at(activities, 0).id - collection = - Enum.map(activities, fn act -> - {:ok, data} = Transmogrifier.prepare_outgoing(act.data) - data - end) + {max_id, min_id, collection} = + if length(activities) > 0 do + { + Enum.at(Enum.reverse(activities), 0).id, + Enum.at(activities, 0).id, + Enum.map(activities, fn act -> + {:ok, data} = Transmogrifier.prepare_outgoing(act.data) + data + end) + } + else + { + 0, + 0, + [] + } + end iri = "#{user.ap_id}/outbox" diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index a809c15b1..6bd4493f5 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -304,6 +304,18 @@ test "it clears `unreachable` federation status of the sender", %{conn: conn} do end describe "/users/:nickname/outbox" do + test "it will not bomb when there is no activity", %{conn: conn} do + user = insert(:user) + + conn = + conn + |> put_req_header("accept", "application/activity+json") + |> get("/users/#{user.nickname}/outbox") + + result = json_response(conn, 200) + assert user.ap_id <> "/outbox" == result["id"] + end + 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"])