From e5454620e6272f58527545c027c6c446116743f6 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 7 Oct 2021 04:49:33 -0600 Subject: [PATCH] Update HomeTimeline api --- app/Http/Controllers/PublicApiController.php | 13 +++++++++---- app/Services/StatusService.php | 7 +++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/PublicApiController.php b/app/Http/Controllers/PublicApiController.php index 64c37513..6a814388 100644 --- a/app/Http/Controllers/PublicApiController.php +++ b/app/Http/Controllers/PublicApiController.php @@ -309,7 +309,7 @@ class PublicApiController extends Controller ->limit($limit) ->get() ->map(function($s) use ($user) { - $status = StatusService::get($s->id); + $status = StatusService::getFull($s->id, $user->profile_id); $status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id); return $status; }); @@ -341,10 +341,15 @@ class PublicApiController extends Controller ->whereLocal(true) ->whereScope('public') ->orderBy('id', 'desc') - ->simplePaginate($limit); + ->limit($limit) + ->get() + ->map(function($s) use ($user) { + $status = StatusService::getFull($s->id, $user->profile_id); + $status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id); + return $status; + }); - $fractal = new Fractal\Resource\Collection($timeline, new StatusTransformer()); - $res = $this->fractal->createData($fractal)->toArray(); + $res = $timeline->toArray(); } return response()->json($res); diff --git a/app/Services/StatusService.php b/app/Services/StatusService.php index 01d287e8..2b550a73 100644 --- a/app/Services/StatusService.php +++ b/app/Services/StatusService.php @@ -40,6 +40,13 @@ class StatusService { }); } + public static function getFull($id, $pid, $publicOnly = true) + { + $res = self::get($id, $publicOnly); + $res['relationship'] = RelationshipService::get($pid, $res['account']['id']); + return $res; + } + public static function del($id) { $status = self::get($id);