From c52c841eac87797b300587d903e78947cd414901 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 26 Aug 2018 13:02:18 -0600 Subject: [PATCH] Update TimelineController, add filters --- app/Http/Controllers/TimelineController.php | 22 ++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/TimelineController.php b/app/Http/Controllers/TimelineController.php index 5cc84530..9cbc579e 100644 --- a/app/Http/Controllers/TimelineController.php +++ b/app/Http/Controllers/TimelineController.php @@ -4,7 +4,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use Auth; -use App\{Follower, Status, User}; +use App\{Follower, Profile, Status, User, UserFilter}; class TimelineController extends Controller { @@ -15,10 +15,16 @@ class TimelineController extends Controller public function personal() { + $pid = Auth::user()->profile->id; // TODO: Use redis for timelines - $following = Follower::whereProfileId(Auth::user()->profile->id)->pluck('following_id'); - $following->push(Auth::user()->profile->id); + $following = Follower::whereProfileId($pid)->pluck('following_id'); + $following->push($pid); + $filtered = UserFilter::whereUserId($pid) + ->whereFilterableType('App\Profile') + ->whereIn('filter_type', ['mute', 'block']) + ->pluck('filterable_id'); $timeline = Status::whereIn('profile_id', $following) + ->whereNotIn('profile_id', $filtered) ->orderBy('id','desc') ->withCount(['comments', 'likes']) ->simplePaginate(20); @@ -30,8 +36,18 @@ class TimelineController extends Controller { // TODO: Use redis for timelines // $timeline = Timeline::build()->local(); + $pid = Auth::user()->profile->id; + + $filtered = UserFilter::whereUserId($pid) + ->whereFilterableType('App\Profile') + ->whereIn('filter_type', ['mute', 'block']) + ->pluck('filterable_id'); + $private = Profile::whereIsPrivate(true)->pluck('id'); + $filtered = $filtered->merge($private); $timeline = Status::whereHas('media') + ->whereNotIn('profile_id', $filtered) ->whereNull('in_reply_to_id') + ->whereNull('reblog_of_id') ->withCount(['comments', 'likes']) ->orderBy('id','desc') ->simplePaginate(20);