Find next item index properly

This commit is contained in:
Jeremy Dormitzer 2019-01-20 18:39:01 -05:00
parent 5e979c4236
commit 4e9a21771a

View File

@ -104,8 +104,9 @@ class CollectionsService
$itemsKey => $pageItems,
'partOf' => $collection['id'],
);
if ( $collectionItems->getFieldValue( $idx ) ) {
$page['next'] = $collection['id'] . "?offset=$idx";
$nextIdx = $this->hasNextItem( $request, $collectionItems, $idx );
if ( $nextIdx ) {
$page['next'] = $collection['id'] . "?offset=$nextIdx";
}
if ( $isOrdered ) {
$page['startIndex'] = $offset;
@ -113,6 +114,20 @@ class CollectionsService
return $page;
}
private function hasNextItem( $request, $collectionItems, $idx )
{
$next = $collectionItems->getFieldValue( $idx );
while ( $next ) {
if ( is_string( $next ) ||
$this->authService->requestAuthorizedToView( $request, $next ) ) {
return $idx;
}
$idx++;
$next = $collectionsItems->getFieldValue( $idx );
}
return false;
}
private function isOrdered( ActivityPubObject $collection )
{
if ( $collection->hasField( 'type' ) &&