From 2881b6626a5153b20b87bcaa9d6ae0a5775d5ff0 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 5 Feb 2023 22:50:12 -0700 Subject: [PATCH] Update ApiV1Controller --- app/Http/Controllers/Api/ApiV1Controller.php | 18 +++++++++++++++++- app/Http/Controllers/PublicApiController.php | 4 ++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index d9dd6a0f4..0923d718f 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -1972,6 +1972,11 @@ class ApiV1Controller extends Controller return $following->push($pid)->toArray(); }); + $includeReplies = false; + if(config('exp.top')) { + $includeReplies = (bool) Redis::zscore('pf:tl:replies', $pid); + } + if(config('instance.timeline.home.cached') && (!$min && !$max)) { $ttl = config('instance.timeline.home.cache_ttl'); $res = Cache::remember( @@ -1980,7 +1985,8 @@ class ApiV1Controller extends Controller function() use( $following, $limit, - $pid + $pid, + $includeReplies ) { return Status::select( 'id', @@ -2002,6 +2008,11 @@ class ApiV1Controller extends Controller 'created_at', 'updated_at' ) + ->when($includeReplies, function($q, $includeReplies) { + return $q; + }, function($q, $includeReplies) { + return $q->whereNull('in_reply_to_id'); + }) ->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album']) ->whereIn('profile_id', $following) ->whereIn('visibility',['public', 'unlisted', 'private']) @@ -2053,6 +2064,11 @@ class ApiV1Controller extends Controller ) ->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album']) ->where('id', $dir, $id) + ->when($includeReplies, function($q, $includeReplies) { + return $q; + }, function($q, $includeReplies) { + return $q->whereNull('in_reply_to_id'); + }) ->whereIn('profile_id', $following) ->whereIn('visibility',['public', 'unlisted', 'private']) ->latest() diff --git a/app/Http/Controllers/PublicApiController.php b/app/Http/Controllers/PublicApiController.php index 18bb7e0b7..5aabb6c99 100644 --- a/app/Http/Controllers/PublicApiController.php +++ b/app/Http/Controllers/PublicApiController.php @@ -472,10 +472,10 @@ class PublicApiController extends Controller // $types = ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album', 'text']; $textOnlyReplies = false; + $textOnlyReplies = (bool) Redis::zscore('pf:tl:replies', $pid); if(config('exp.top')) { $textOnlyPosts = (bool) Redis::zscore('pf:tl:top', $pid); - $textOnlyReplies = (bool) Redis::zscore('pf:tl:replies', $pid); if($textOnlyPosts) { array_push($types, 'text'); @@ -587,7 +587,7 @@ class PublicApiController extends Controller 'updated_at' ) ->whereIn('type', $types) - ->when($textOnlyReplies != true, function($q, $textOnlyReplies) { + ->when(!$textOnlyReplies, function($q, $textOnlyReplies) { return $q->whereNull('in_reply_to_id'); }) ->where('id', $dir, $id)