pixelfed/app/Http/Controllers/TimelineController.php

66 lines
2.1 KiB
PHP
Raw Normal View History

2018-04-16 01:56:17 +00:00
<?php
namespace App\Http\Controllers;
2018-08-28 03:07:36 +00:00
use App\Follower;
use App\Profile;
use App\Status;
use App\User;
use App\UserFilter;
use Auth;
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
}
public function personal()
{
2018-08-28 03:07:36 +00:00
$pid = Auth::user()->profile->id;
// TODO: Use redis for timelines
$following = Follower::whereProfileId($pid)->pluck('following_id');
$following->push($pid);
$filtered = UserFilter::whereUserId($pid)
2018-08-26 19:02:18 +00:00
->whereFilterableType('App\Profile')
->whereIn('filter_type', ['mute', 'block'])
->pluck('filterable_id');
2018-08-28 03:07:36 +00:00
$timeline = Status::whereIn('profile_id', $following)
2018-08-26 19:02:18 +00:00
->whereNotIn('profile_id', $filtered)
2018-10-10 01:23:42 +00:00
->whereVisibility('public')
->orderBy('created_at', 'desc')
2018-08-16 02:03:32 +00:00
->withCount(['comments', 'likes'])
2018-08-10 05:01:01 +00:00
->simplePaginate(20);
2018-08-28 03:07:36 +00:00
$type = 'personal';
return view('timeline.template', compact('timeline', 'type'));
2018-04-16 01:56:17 +00:00
}
public function local()
{
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-08-28 03:07:36 +00:00
$filtered = UserFilter::whereUserId($pid)
2018-08-26 19:02:18 +00:00
->whereFilterableType('App\Profile')
->whereIn('filter_type', ['mute', 'block'])
->pluck('filterable_id');
2018-08-28 03:07:36 +00:00
$private = Profile::whereIsPrivate(true)->pluck('id');
$filtered = $filtered->merge($private);
$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')
->whereVisibility('public')
2018-08-16 02:03:32 +00:00
->withCount(['comments', 'likes'])
->orderBy('created_at', 'desc')
2018-08-10 05:01:01 +00:00
->simplePaginate(20);
2018-08-28 03:07:36 +00:00
$type = 'local';
2018-08-28 03:07:36 +00:00
return view('timeline.template', compact('timeline', 'type'));
}
2018-04-16 01:56:17 +00:00
}