Update TimelineController

This commit is contained in:
Daniel Supernault 2018-11-15 20:26:10 -07:00
parent 8fecceed51
commit 53e8da4837
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
1 changed files with 8 additions and 30 deletions

View File

@ -2,7 +2,7 @@
namespace App\Http\Controllers;
use Auth;
use Auth, Cache;
use App\Follower;
use App\Profile;
use App\Status;
@ -18,30 +18,6 @@ class TimelineController extends Controller
$this->middleware('twofactor');
}
public function personal(Request $request)
{
$this->validate($request,[
'page' => 'nullable|integer|max:20'
]);
$pid = Auth::user()->profile->id;
// TODO: Use redis for timelines
$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)
->whereVisibility('public')
->orderBy('created_at', 'desc')
->withCount(['comments', 'likes'])
->simplePaginate(10);
$type = 'personal';
return view('timeline.template', compact('timeline', 'type'));
}
public function local(Request $request)
{
$this->validate($request,[
@ -51,12 +27,14 @@ class TimelineController extends Controller
// $timeline = Timeline::build()->local();
$pid = Auth::user()->profile->id;
$filtered = UserFilter::whereUserId($pid)
->whereFilterableType('App\Profile')
->whereIn('filter_type', ['mute', 'block'])
->pluck('filterable_id');
$filtered = Cache::rememberForever("user:filter:list:$pid", function() use($pid) {
return UserFilter::whereUserId($pid)
->whereFilterableType('App\Profile')
->whereIn('filter_type', ['mute', 'block'])
->pluck('filterable_id')->toArray();
});
$private = Profile::whereIsPrivate(true)->pluck('id');
$filtered = $filtered->merge($private);
$filtered = array_merge($private->toArray(), $filtered);
$timeline = Status::whereHas('media')
->whereNotIn('profile_id', $filtered)
->whereNull('in_reply_to_id')