forked from AkkomaGang/akkoma
Merge branch 'fix/adminapi-user-status-pagination' into 'develop'
Support pagination in AdminAPI for user statuses See merge request pleroma/pleroma!3226
This commit is contained in:
commit
70e8ef2c46
3 changed files with 22 additions and 5 deletions
|
@ -603,12 +603,18 @@ def fetch_user_activities(user, reading_user, params \\ %{}) do
|
||||||
|> Map.put(:muting_user, reading_user)
|
|> Map.put(:muting_user, reading_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
pagination_type =
|
||||||
|
cond do
|
||||||
|
!Map.has_key?(params, :offset) -> :keyset
|
||||||
|
true -> :offset
|
||||||
|
end
|
||||||
|
|
||||||
%{
|
%{
|
||||||
godmode: params[:godmode],
|
godmode: params[:godmode],
|
||||||
reading_user: reading_user
|
reading_user: reading_user
|
||||||
}
|
}
|
||||||
|> user_activities_recipients()
|
|> user_activities_recipients()
|
||||||
|> fetch_activities(params)
|
|> fetch_activities(params, pagination_type)
|
||||||
|> Enum.reverse()
|
|> Enum.reverse()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -103,11 +103,12 @@ def list_user_statuses(%{assigns: %{user: admin}} = conn, %{"nickname" => nickna
|
||||||
godmode = params["godmode"] == "true" || params["godmode"] == true
|
godmode = params["godmode"] == "true" || params["godmode"] == true
|
||||||
|
|
||||||
with %User{} = user <- User.get_cached_by_nickname_or_id(nickname, for: admin) do
|
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 =
|
activities =
|
||||||
ActivityPub.fetch_user_activities(user, nil, %{
|
ActivityPub.fetch_user_activities(user, nil, %{
|
||||||
limit: page_size,
|
limit: page_size,
|
||||||
|
offset: (page - 1) * page_size,
|
||||||
godmode: godmode,
|
godmode: godmode,
|
||||||
exclude_reblogs: not with_reblogs
|
exclude_reblogs: not with_reblogs
|
||||||
})
|
})
|
||||||
|
|
|
@ -422,10 +422,20 @@ test "renders user's statuses", %{conn: conn, user: user} do
|
||||||
assert json_response(conn, 200) |> length() == 3
|
assert json_response(conn, 200) |> length() == 3
|
||||||
end
|
end
|
||||||
|
|
||||||
test "renders user's statuses with a limit", %{conn: conn, user: user} do
|
test "renders user's statuses with pagination", %{conn: conn, user: user} do
|
||||||
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses?page_size=2")
|
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
|
end
|
||||||
|
|
||||||
test "doesn't return private statuses by default", %{conn: conn, user: user} do
|
test "doesn't return private statuses by default", %{conn: conn, user: user} do
|
||||||
|
|
Loading…
Reference in a new issue