mirror of https://github.com/pixelfed/pixelfed.git
Merge pull request #4161 from pixelfed/staging
Update ApiV1Controller, fix account statuses and bookmark pagination
This commit is contained in:
commit
5dff199695
|
@ -619,13 +619,20 @@ class ApiV1Controller extends Controller
|
||||||
->orderByDesc('id')
|
->orderByDesc('id')
|
||||||
->get()
|
->get()
|
||||||
->map(function($s) use($user, $napi, $profile) {
|
->map(function($s) use($user, $napi, $profile) {
|
||||||
$status = $napi ? StatusService::get($s->id, false) : StatusService::getMastodon($s->id, false);
|
try {
|
||||||
|
$status = $napi ? StatusService::get($s->id, false) : StatusService::getMastodon($s->id, false);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$status = false;
|
||||||
|
}
|
||||||
|
|
||||||
if($profile) {
|
if($profile) {
|
||||||
$status['account'] = $profile;
|
$status['account'] = $profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($user && $status) {
|
if($user && $status) {
|
||||||
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
||||||
|
$status['reblogged'] = (bool) ReblogService::get($user->profile_id, $s->id);
|
||||||
|
$status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $s->id);
|
||||||
}
|
}
|
||||||
return $status;
|
return $status;
|
||||||
})
|
})
|
||||||
|
@ -2975,20 +2982,36 @@ class ApiV1Controller extends Controller
|
||||||
$dir = $min_id ? '>' : '<';
|
$dir = $min_id ? '>' : '<';
|
||||||
$id = $min_id ?? $max_id;
|
$id = $min_id ?? $max_id;
|
||||||
|
|
||||||
$bookmarks = Bookmark::whereProfileId($pid)
|
$bookmarkQuery = Bookmark::whereProfileId($pid)
|
||||||
->when($id, function($query, $id) use($dir) {
|
->orderByDesc('id')
|
||||||
return $query->where('status_id', $dir, $id);
|
->cursorPaginate($limit);
|
||||||
})
|
|
||||||
->limit($limit)
|
$bookmarks = $bookmarkQuery->map(function($bookmark) {
|
||||||
->pluck('status_id')
|
return \App\Services\StatusService::getMastodon($bookmark->status_id);
|
||||||
->map(function($id) {
|
|
||||||
return \App\Services\StatusService::getMastodon($id);
|
|
||||||
})
|
})
|
||||||
->filter()
|
->filter()
|
||||||
->values()
|
->values()
|
||||||
->toArray();
|
->toArray();
|
||||||
|
|
||||||
return $this->json($bookmarks);
|
$links = null;
|
||||||
|
$headers = [];
|
||||||
|
|
||||||
|
if($bookmarkQuery->nextCursor()) {
|
||||||
|
$links .= '<'.$bookmarkQuery->nextPageUrl().'&limit='.$limit.'>; rel="next"';
|
||||||
|
}
|
||||||
|
|
||||||
|
if($bookmarkQuery->previousCursor()) {
|
||||||
|
if($links != null) {
|
||||||
|
$links .= ', ';
|
||||||
|
}
|
||||||
|
$links .= '<'.$bookmarkQuery->previousPageUrl().'&limit='.$limit.'>; rel="prev"';
|
||||||
|
}
|
||||||
|
|
||||||
|
if($links) {
|
||||||
|
$headers = ['Link' => $links];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->json($bookmarks, 200, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue