From a0bde855bdbca0b0a927468e8e994b792054ad65 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 18 Jun 2020 21:03:35 -0600 Subject: [PATCH] Update ApiV1Controller, add status ancestor and descendant context --- app/Http/Controllers/Api/ApiV1Controller.php | 26 ++++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 17d6fc269..4bc055ed8 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -1525,11 +1525,27 @@ class ApiV1Controller extends Controller } } - // Return empty response since we don't handle threading like this - $res = [ - 'ancestors' => [], - 'descendants' => [] - ]; + if($status->comments_disabled) { + $res = [ + 'ancestors' => [], + 'descendants' => [] + ]; + } else { + $ancestors = $status->parent(); + if($ancestors) { + $ares = new Fractal\Resource\Item($ancestors, new StatusTransformer()); + $ancestors = $this->fractal->createData($ares)->toArray(); + } else { + $ancestors = []; + } + $descendants = Status::whereInReplyToId($id)->latest()->limit(20)->get(); + $dres = new Fractal\Resource\Collection($descendants, new StatusTransformer()); + $descendants = $this->fractal->createData($dres)->toArray(); + $res = [ + 'ancestors' => $ancestors, + 'descendants' => $descendants + ]; + } return response()->json($res); }