mirror of
https://github.com/pixelfed/pixelfed.git
synced 2025-01-24 21:40:47 +00:00
Update Controllers, add last_active_at logic
This commit is contained in:
parent
cc3053ed5d
commit
96afc3e781
2 changed files with 41 additions and 1 deletions
|
@ -1320,6 +1320,15 @@ class ApiV1Controller extends Controller
|
|||
$min = $request->input('min_id');
|
||||
$max = $request->input('max_id');
|
||||
$limit = $request->input('limit') ?? 3;
|
||||
$user = $request->user();
|
||||
|
||||
$key = 'user:last_active_at:id:'.$user->id;
|
||||
$ttl = now()->addMinutes(5);
|
||||
Cache::remember($key, $ttl, function() use($user) {
|
||||
$user->last_active_at = now();
|
||||
$user->save();
|
||||
return;
|
||||
});
|
||||
|
||||
$pid = $request->user()->profile_id;
|
||||
|
||||
|
@ -1424,6 +1433,15 @@ class ApiV1Controller extends Controller
|
|||
$min = $request->input('min_id');
|
||||
$max = $request->input('max_id');
|
||||
$limit = $request->input('limit') ?? 3;
|
||||
$user = $request->user();
|
||||
|
||||
$key = 'user:last_active_at:id:'.$user->id;
|
||||
$ttl = now()->addMinutes(5);
|
||||
Cache::remember($key, $ttl, function() use($user) {
|
||||
$user->last_active_at = now();
|
||||
$user->save();
|
||||
return;
|
||||
});
|
||||
|
||||
if($min || $max) {
|
||||
$dir = $min ? '>' : '<';
|
||||
|
@ -1452,6 +1470,7 @@ class ApiV1Controller extends Controller
|
|||
->with('profile', 'hashtags', 'mentions')
|
||||
->where('id', $dir, $id)
|
||||
->whereScope('public')
|
||||
->where('created_at', '>', now()->subDays(14))
|
||||
->latest()
|
||||
->limit($limit)
|
||||
->get();
|
||||
|
@ -1479,6 +1498,7 @@ class ApiV1Controller extends Controller
|
|||
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
|
||||
->with('profile', 'hashtags', 'mentions')
|
||||
->whereScope('public')
|
||||
->where('created_at', '>', now()->subDays(14))
|
||||
->latest()
|
||||
->simplePaginate($limit);
|
||||
}
|
||||
|
|
|
@ -272,8 +272,17 @@ class PublicApiController extends Controller
|
|||
$min = $request->input('min_id');
|
||||
$max = $request->input('max_id');
|
||||
$limit = $request->input('limit') ?? 3;
|
||||
$user = $request->user();
|
||||
|
||||
$filtered = UserFilter::whereUserId(Auth::user()->profile_id)
|
||||
$key = 'user:last_active_at:id:'.$user->id;
|
||||
$ttl = now()->addMinutes(5);
|
||||
Cache::remember($key, $ttl, function() use($user) {
|
||||
$user->last_active_at = now();
|
||||
$user->save();
|
||||
return;
|
||||
});
|
||||
|
||||
$filtered = UserFilter::whereUserId($user->profile_id)
|
||||
->whereFilterableType('App\Profile')
|
||||
->whereIn('filter_type', ['mute', 'block'])
|
||||
->pluck('filterable_id')->toArray();
|
||||
|
@ -305,6 +314,7 @@ class PublicApiController extends Controller
|
|||
->whereNotIn('profile_id', $filtered)
|
||||
->whereLocal(true)
|
||||
->whereScope('public')
|
||||
->where('created_at', '>', now()->subDays(14))
|
||||
->orderBy('created_at', 'desc')
|
||||
->limit($limit)
|
||||
->get();
|
||||
|
@ -333,6 +343,7 @@ class PublicApiController extends Controller
|
|||
->with('profile', 'hashtags', 'mentions')
|
||||
->whereLocal(true)
|
||||
->whereScope('public')
|
||||
->where('created_at', '>', now()->subDays(14))
|
||||
->orderBy('created_at', 'desc')
|
||||
->simplePaginate($limit);
|
||||
}
|
||||
|
@ -360,6 +371,15 @@ class PublicApiController extends Controller
|
|||
$min = $request->input('min_id');
|
||||
$max = $request->input('max_id');
|
||||
$limit = $request->input('limit') ?? 3;
|
||||
$user = $request->user();
|
||||
|
||||
$key = 'user:last_active_at:id:'.$user->id;
|
||||
$ttl = now()->addMinutes(5);
|
||||
Cache::remember($key, $ttl, function() use($user) {
|
||||
$user->last_active_at = now();
|
||||
$user->save();
|
||||
return;
|
||||
});
|
||||
|
||||
// TODO: Use redis for timelines
|
||||
// $timeline = Timeline::build()->local();
|
||||
|
|
Loading…
Reference in a new issue