1
0
Fork 0
forked from mirror/pixelfed
pixelfed/app/Http/Controllers/TimelineController.php

59 lines
1.9 KiB
PHP
Raw Normal View History

2018-04-16 01:56:17 +00:00
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth;
2018-08-26 19:02:18 +00:00
use App\{Follower, Profile, Status, User, UserFilter};
2018-04-16 01:56:17 +00:00
class TimelineController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function personal()
{
2018-08-26 19:02:18 +00:00
$pid = Auth::user()->profile->id;
// TODO: Use redis for timelines
2018-08-26 19:02:18 +00:00
$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');
2018-08-10 05:01:01 +00:00
$timeline = Status::whereIn('profile_id', $following)
2018-08-26 19:02:18 +00:00
->whereNotIn('profile_id', $filtered)
2018-06-04 01:40:19 +00:00
->orderBy('id','desc')
2018-08-16 02:03:32 +00:00
->withCount(['comments', 'likes'])
2018-08-10 05:01:01 +00:00
->simplePaginate(20);
$type = 'personal';
return view('timeline.template', compact('timeline', 'type'));
2018-04-16 01:56:17 +00:00
}
public function local()
{
// TODO: Use redis for timelines
2018-08-10 05:01:01 +00:00
// $timeline = Timeline::build()->local();
2018-08-26 19:02:18 +00:00
$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);
2018-06-04 01:40:19 +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-08-16 02:03:32 +00:00
->withCount(['comments', 'likes'])
2018-06-04 01:40:19 +00:00
->orderBy('id','desc')
2018-08-10 05:01:01 +00:00
->simplePaginate(20);
$type = 'local';
return view('timeline.template', compact('timeline', 'type'));
}
2018-04-16 01:56:17 +00:00
}