2018-04-16 01:56:17 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2018-11-16 03:26:10 +00:00
|
|
|
use Auth, Cache;
|
2018-08-28 03:07:36 +00:00
|
|
|
use App\Follower;
|
|
|
|
use App\Profile;
|
|
|
|
use App\Status;
|
|
|
|
use App\User;
|
|
|
|
use App\UserFilter;
|
2018-11-09 01:27:38 +00:00
|
|
|
use Illuminate\Http\Request;
|
2018-04-16 01:56:17 +00:00
|
|
|
|
|
|
|
class TimelineController extends Controller
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
2018-08-28 03:07:36 +00:00
|
|
|
$this->middleware('auth');
|
2018-09-16 05:15:45 +00:00
|
|
|
$this->middleware('twofactor');
|
2018-04-16 01:56:17 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 01:27:38 +00:00
|
|
|
public function local(Request $request)
|
2018-05-31 22:05:39 +00:00
|
|
|
{
|
2018-11-09 01:27:38 +00:00
|
|
|
$this->validate($request,[
|
|
|
|
'page' => 'nullable|integer|max:20'
|
|
|
|
]);
|
2018-08-28 03:07:36 +00:00
|
|
|
// TODO: Use redis for timelines
|
|
|
|
// $timeline = Timeline::build()->local();
|
|
|
|
$pid = Auth::user()->profile->id;
|
2018-08-26 19:02:18 +00:00
|
|
|
|
2018-11-20 02:00:21 +00:00
|
|
|
$private = Profile::whereIsPrivate(true)->where('id', '!=', $pid)->pluck('id');
|
|
|
|
$filters = UserFilter::whereUserId($pid)
|
|
|
|
->whereFilterableType('App\Profile')
|
|
|
|
->whereIn('filter_type', ['mute', 'block'])
|
|
|
|
->pluck('filterable_id')->toArray();
|
|
|
|
$filtered = array_merge($private->toArray(), $filters);
|
|
|
|
|
2018-08-28 03:07:36 +00:00
|
|
|
$timeline = Status::whereHas('media')
|
2018-08-26 19:02:18 +00:00
|
|
|
->whereNotIn('profile_id', $filtered)
|
2018-06-04 01:40:19 +00:00
|
|
|
->whereNull('in_reply_to_id')
|
2018-08-26 19:02:18 +00:00
|
|
|
->whereNull('reblog_of_id')
|
2018-09-01 01:50:37 +00:00
|
|
|
->whereVisibility('public')
|
2018-08-16 02:03:32 +00:00
|
|
|
->withCount(['comments', 'likes'])
|
2018-09-12 02:55:19 +00:00
|
|
|
->orderBy('created_at', 'desc')
|
2018-11-09 01:27:38 +00:00
|
|
|
->simplePaginate(10);
|
2018-08-28 03:07:36 +00:00
|
|
|
$type = 'local';
|
2018-05-31 22:05:39 +00:00
|
|
|
|
2018-08-28 03:07:36 +00:00
|
|
|
return view('timeline.template', compact('timeline', 'type'));
|
|
|
|
}
|
2018-04-16 01:56:17 +00:00
|
|
|
}
|