From f0e648b7b8ae933e9a37fd3e26d8f6ab72f4f812 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 27 Jan 2023 00:53:47 -0700 Subject: [PATCH] Update ApiV1Controller, fix bookmarks endpoint --- app/Http/Controllers/Api/ApiV1Controller.php | 30 +++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 11ab3a01..b35ce35f 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -2935,24 +2935,20 @@ class ApiV1Controller extends Controller $dir = $min_id ? '>' : '<'; $id = $min_id ?? $max_id; - if($id) { - $bookmarks = Bookmark::whereProfileId($pid) - ->where('status_id', $dir, $id) - ->limit($limit) - ->pluck('status_id'); - } else { - $bookmarks = Bookmark::whereProfileId($pid) - ->latest() - ->limit($limit) - ->pluck('status_id'); - } + $bookmarks = Bookmark::whereProfileId($pid) + ->when($id, function($id, $query) use($dir) { + return $query->where('status_id', $dir, $id); + }) + ->limit($limit) + ->pluck('status_id') + ->map(function($id) { + return \App\Services\StatusService::getMastodon($id); + }) + ->filter() + ->values() + ->toArray(); - $res = []; - foreach($bookmarks as $id) { - $res[] = \App\Services\StatusService::getMastodon($id); - } - - return $this->json($res); + return $this->json($bookmarks); } /**