1
0
Fork 0
forked from mirror/pixelfed

Update PublicApiController, add recent feed support to home timeline

This commit is contained in:
Daniel Supernault 2021-06-01 20:03:59 -06:00
parent f3bf2fd41e
commit 1e230e80fb
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -12,6 +12,7 @@ use App\{
Profile,
StatusHashtag,
Status,
StatusView,
UserFilter
};
use Auth,Cache;
@ -376,9 +377,13 @@ class PublicApiController extends Controller
'page' => 'nullable|integer|max:40',
'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
'limit' => 'nullable|integer|max:40'
'limit' => 'nullable|integer|max:40',
'recent_feed' => 'nullable',
'recent_min' => 'nullable|integer'
]);
$recentFeed = $request->input('recent_feed') == 'true';
$recentFeedMin = $request->input('recent_min');
$page = $request->input('page');
$min = $request->input('min_id');
$max = $request->input('max_id');
@ -393,29 +398,21 @@ class PublicApiController extends Controller
return;
});
// TODO: Use redis for timelines
// $timeline = Timeline::build()->local();
$pid = Auth::user()->profile->id;
$pid = Auth::user()->profile_id;
$following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function() use($pid) {
$following = Follower::whereProfileId($pid)->pluck('following_id');
return $following->push($pid)->toArray();
});
// $private = Cache::remember('profiles:private', now()->addMinutes(1440), function() {
// return Profile::whereIsPrivate(true)
// ->orWhere('unlisted', true)
// ->orWhere('status', '!=', null)
// ->pluck('id');
// });
// $private = $private->diff($following)->flatten();
// $filters = UserFilter::whereUserId($pid)
// ->whereFilterableType('App\Profile')
// ->whereIn('filter_type', ['mute', 'block'])
// ->pluck('filterable_id')->toArray();
// $filtered = array_merge($private->toArray(), $filters);
if($recentFeed == true) {
$key = 'profile:home-timeline-cursor:'.$user->id;
$ttl = now()->addMinutes(30);
$min = Cache::remember($key, $ttl, function() use($pid) {
$res = StatusView::whereProfileId($pid)->orderByDesc('status_id')->first();
return $res ? $res->status_id : null;
});
}
$filtered = Auth::check() ? UserFilterService::filters(Auth::user()->profile_id) : [];