From 4c5f75f4e96b8ee8ab1e37b03d46f4e7ead870ac Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 30 Dec 2020 14:36:04 -0600 Subject: [PATCH] Support pagination in AdminAPI for user statuses --- .../controllers/admin_api_controller.ex | 5 +++-- .../controllers/admin_api_controller_test.exs | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex b/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex index 75525104f..9086c4928 100644 --- a/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex @@ -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 }) diff --git a/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs b/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs index e50d1425b..90b25b782 100644 --- a/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs @@ -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 -- 2.45.2