Fix: Fixing an outbox related bug when local user activity is empty
authorKZ <kenneth.zhao@gmail.com>
Fri, 22 Feb 2019 04:37:48 +0000 (04:37 +0000)
committerkaniini <nenolod@gmail.com>
Fri, 22 Feb 2019 04:37:48 +0000 (04:37 +0000)
lib/pleroma/web/activity_pub/views/user_view.ex
test/web/activity_pub/activity_pub_controller_test.exs

index c8e15498986d71a91a1c27cd6db6691d4bcc2b3d..415cbd47a5ef98713034623b5ae7c4d5231b859c 100644 (file)
@@ -188,14 +188,24 @@ defmodule Pleroma.Web.ActivityPub.UserView 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"
 
index a809c15b1805ce7cbbd4e8ac4e9e602352783f4b..6bd4493f5b47d0b325364b04f9e29a0df323966e 100644 (file)
@@ -304,6 +304,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest 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"])