From 1e230e80fba0762d6d19264957817427d784b837 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 1 Jun 2021 20:03:59 -0600 Subject: [PATCH] Update PublicApiController, add recent feed support to home timeline --- app/Http/Controllers/PublicApiController.php | 33 +++++++++----------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/app/Http/Controllers/PublicApiController.php b/app/Http/Controllers/PublicApiController.php index afeffa12..a6a44a52 100644 --- a/app/Http/Controllers/PublicApiController.php +++ b/app/Http/Controllers/PublicApiController.php @@ -12,6 +12,7 @@ use App\{ Profile, StatusHashtag, Status, + StatusView, UserFilter }; use Auth,Cache; @@ -376,9 +377,13 @@ class PublicApiController extends Controller 'page' => 'nullable|integer|max:40', 'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX, 'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX, - 'limit' => 'nullable|integer|max:40' + 'limit' => 'nullable|integer|max:40', + 'recent_feed' => 'nullable', + 'recent_min' => 'nullable|integer' ]); + $recentFeed = $request->input('recent_feed') == 'true'; + $recentFeedMin = $request->input('recent_min'); $page = $request->input('page'); $min = $request->input('min_id'); $max = $request->input('max_id'); @@ -393,29 +398,21 @@ class PublicApiController extends Controller return; }); - // TODO: Use redis for timelines - // $timeline = Timeline::build()->local(); - $pid = Auth::user()->profile->id; + $pid = Auth::user()->profile_id; $following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function() use($pid) { $following = Follower::whereProfileId($pid)->pluck('following_id'); return $following->push($pid)->toArray(); }); - // $private = Cache::remember('profiles:private', now()->addMinutes(1440), function() { - // return Profile::whereIsPrivate(true) - // ->orWhere('unlisted', true) - // ->orWhere('status', '!=', null) - // ->pluck('id'); - // }); - - // $private = $private->diff($following)->flatten(); - - // $filters = UserFilter::whereUserId($pid) - // ->whereFilterableType('App\Profile') - // ->whereIn('filter_type', ['mute', 'block']) - // ->pluck('filterable_id')->toArray(); - // $filtered = array_merge($private->toArray(), $filters); + if($recentFeed == true) { + $key = 'profile:home-timeline-cursor:'.$user->id; + $ttl = now()->addMinutes(30); + $min = Cache::remember($key, $ttl, function() use($pid) { + $res = StatusView::whereProfileId($pid)->orderByDesc('status_id')->first(); + return $res ? $res->status_id : null; + }); + } $filtered = Auth::check() ? UserFilterService::filters(Auth::user()->profile_id) : [];