add pager to followers endpoint

This commit is contained in:
Matthias Pfefferle 2023-07-07 15:02:34 +02:00
parent d00b7b54f2
commit 4b8ffc874a

View file

@ -58,6 +58,8 @@ class Followers {
return $user; return $user;
} }
$page = $request->get_param( 'page', 1 );
/* /*
* Action triggerd prior to the ActivityPub profile being created and sent to the client * Action triggerd prior to the ActivityPub profile being created and sent to the client
*/ */
@ -72,15 +74,22 @@ class Followers {
$json->actor = $user->get_id(); $json->actor = $user->get_id();
$json->type = 'OrderedCollectionPage'; $json->type = 'OrderedCollectionPage';
$json->partOf = get_rest_url_by_path( sprintf( 'users/%d/followers', $user->get__id() ) ); // phpcs:ignore
$json->first = $json->partOf; // phpcs:ignore
$json->totalItems = FollowerCollection::count_followers( $user->get__id() ); // phpcs:ignore $json->totalItems = FollowerCollection::count_followers( $user->get__id() ); // phpcs:ignore
$json->partOf = get_rest_url_by_path( sprintf( 'users/%d/followers', $user->get__id() ) ); // phpcs:ignore
$json->first = \add_query_arg( 'page', 1, $json->partOf ); // phpcs:ignore
$json->last = \add_query_arg( 'page', \ceil ( $json->totalItems / 20 ), $json->partOf ); // phpcs:ignore
if ( $page && ( ( \ceil ( $json->totalItems / 20 ) ) >= $page ) ) { // phpcs:ignore
$json->next = \add_query_arg( 'page', $page + 1, $json->partOf ); // phpcs:ignore
}
// phpcs:ignore // phpcs:ignore
$json->orderedItems = array_map( $json->orderedItems = array_map(
function( $item ) { function( $item ) {
return $item->get_url(); return $item->get_url();
}, },
FollowerCollection::get_followers( $user->get__id() ) FollowerCollection::get_followers( $user->get__id(), 20, $page )
); );
$response = new WP_REST_Response( $json, 200 ); $response = new WP_REST_Response( $json, 200 );
@ -99,6 +108,7 @@ class Followers {
$params['page'] = array( $params['page'] = array(
'type' => 'integer', 'type' => 'integer',
'default' => 1,
); );
$params['user_id'] = array( $params['user_id'] = array(