Support pagination in AdminAPI for user statuses
authorMark Felder <feld@feld.me>
Wed, 30 Dec 2020 20:36:04 +0000 (14:36 -0600)
committerMark Felder <feld@feld.me>
Wed, 30 Dec 2020 21:18:54 +0000 (15:18 -0600)
lib/pleroma/web/admin_api/controllers/admin_api_controller.ex
test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs

index 75525104ff98a29788219e930e023dd3d7e147cc..9086c49286d8e24878bc5b7fa51c389e178e4552 100644 (file)
@@ -103,11 +103,12 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
     godmode = params["godmode"] == "true" || params["godmode"] == true
 
     with %User{} = user <- User.get_cached_by_nickname_or_id(nickname, for: admin) do
-      {_, page_size} = page_params(params)
+      {page, page_size} = page_params(params)
 
       activities =
-        ActivityPub.fetch_user_activities(user, nil, %{
+        ActivityPub.fetch_statuses(user, %{
           limit: page_size,
+          offset: (page - 1) * page_size,
           godmode: godmode,
           exclude_reblogs: not with_reblogs
         })
index e50d1425b78c068851f434f03f1bf7222bf57d99..90b25b782a30b9a3390571051a13bc2f68f2737a 100644 (file)
@@ -422,10 +422,20 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
       assert json_response(conn, 200) |> length() == 3
     end
 
-    test "renders user's statuses with a limit", %{conn: conn, user: user} do
-      conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses?page_size=2")
+    test "renders user's statuses with pagination", %{conn: conn, user: user} do
+      conn1 = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses?page_size=1&page=1")
 
-      assert json_response(conn, 200) |> length() == 2
+      response1 = json_response(conn1, 200)
+
+      assert response1 |> length() == 1
+
+      conn2 = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses?page_size=1&page=2")
+
+      response2 = json_response(conn2, 200)
+
+      assert response2 |> length() == 1
+
+      refute response1 == response2
     end
 
     test "doesn't return private statuses by default", %{conn: conn, user: user} do