Update ApiV1Controller, set last_active_at

This commit is contained in:
Daniel Supernault 2023-12-13 06:49:00 -07:00
parent ebbd98e743
commit b641954549
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1

View file

@ -189,6 +189,7 @@ class ApiV1Controller extends Controller
abort_if(!$user, 403); abort_if(!$user, 403);
abort_if($user->status != null, 403); abort_if($user->status != null, 403);
AccountService::setLastActive($user->id);
$res = $request->has(self::PF_API_ENTITY_KEY) ? AccountService::get($user->profile_id) : AccountService::getMastodon($user->profile_id); $res = $request->has(self::PF_API_ENTITY_KEY) ? AccountService::get($user->profile_id) : AccountService::getMastodon($user->profile_id);
@ -247,6 +248,7 @@ class ApiV1Controller extends Controller
]); ]);
$user = $request->user(); $user = $request->user();
AccountService::setLastActive($user->id);
$profile = $user->profile; $profile = $user->profile;
$settings = $user->settings; $settings = $user->settings;
@ -754,6 +756,7 @@ class ApiV1Controller extends Controller
abort_if(!$request->user(), 403); abort_if(!$request->user(), 403);
$user = $request->user(); $user = $request->user();
AccountService::setLastActive($user->id);
$target = Profile::where('id', '!=', $user->profile_id) $target = Profile::where('id', '!=', $user->profile_id)
->whereNull('status') ->whereNull('status')
@ -838,6 +841,7 @@ class ApiV1Controller extends Controller
abort_if(!$request->user(), 403); abort_if(!$request->user(), 403);
$user = $request->user(); $user = $request->user();
AccountService::setLastActive($user->id);
$target = Profile::where('id', '!=', $user->profile_id) $target = Profile::where('id', '!=', $user->profile_id)
->whereNull('status') ->whereNull('status')
@ -941,6 +945,7 @@ class ApiV1Controller extends Controller
]); ]);
$user = $request->user(); $user = $request->user();
AccountService::setLastActive($user->id);
$query = $request->input('q'); $query = $request->input('q');
$limit = $request->input('limit') ?? 20; $limit = $request->input('limit') ?? 20;
$resolve = (bool) $request->input('resolve', false); $resolve = (bool) $request->input('resolve', false);
@ -1013,6 +1018,7 @@ class ApiV1Controller extends Controller
$user = $request->user(); $user = $request->user();
$pid = $user->profile_id ?? $user->profile->id; $pid = $user->profile_id ?? $user->profile->id;
AccountService::setLastActive($user->id);
if(intval($id) === intval($pid)) { if(intval($id) === intval($pid)) {
abort(400, 'You cannot block yourself'); abort(400, 'You cannot block yourself');
@ -1105,6 +1111,7 @@ class ApiV1Controller extends Controller
$user = $request->user(); $user = $request->user();
$pid = $user->profile_id ?? $user->profile->id; $pid = $user->profile_id ?? $user->profile->id;
AccountService::setLastActive($user->id);
if(intval($id) === intval($pid)) { if(intval($id) === intval($pid)) {
abort(400, 'You cannot unblock yourself'); abort(400, 'You cannot unblock yourself');
@ -1237,6 +1244,8 @@ class ApiV1Controller extends Controller
$user = $request->user(); $user = $request->user();
AccountService::setLastActive($user->id);
$status = StatusService::getMastodon($id, false); $status = StatusService::getMastodon($id, false);
abort_unless($status, 400); abort_unless($status, 400);
@ -1296,6 +1305,8 @@ class ApiV1Controller extends Controller
$user = $request->user(); $user = $request->user();
AccountService::setLastActive($user->id);
$status = Status::findOrFail($id); $status = Status::findOrFail($id);
if(intval($status->profile_id) !== intval($user->profile_id)) { if(intval($status->profile_id) !== intval($user->profile_id)) {
@ -1611,6 +1622,7 @@ class ApiV1Controller extends Controller
]); ]);
$user = $request->user(); $user = $request->user();
AccountService::setLastActive($user->id);
if($user->last_active_at == null) { if($user->last_active_at == null) {
return []; return [];
@ -1732,6 +1744,7 @@ class ApiV1Controller extends Controller
]); ]);
$user = $request->user(); $user = $request->user();
AccountService::setLastActive($user->id);
$media = Media::whereUserId($user->id) $media = Media::whereUserId($user->id)
->whereProfileId($user->profile_id) ->whereProfileId($user->profile_id)
@ -1778,6 +1791,7 @@ class ApiV1Controller extends Controller
abort_if(!$request->user(), 403); abort_if(!$request->user(), 403);
$user = $request->user(); $user = $request->user();
AccountService::setLastActive($user->id);
$media = Media::whereUserId($user->id) $media = Media::whereUserId($user->id)
->whereNull('status_id') ->whereNull('status_id')
@ -1821,6 +1835,8 @@ class ApiV1Controller extends Controller
return []; return [];
} }
AccountService::setLastActive($user->id);
if(empty($request->file('file'))) { if(empty($request->file('file'))) {
return response('', 422); return response('', 422);
} }
@ -2065,6 +2081,8 @@ class ApiV1Controller extends Controller
'min_id' => 'nullable|integer|min:1|max:'.PHP_INT_MAX, 'min_id' => 'nullable|integer|min:1|max:'.PHP_INT_MAX,
'max_id' => 'nullable|integer|min:1|max:'.PHP_INT_MAX, 'max_id' => 'nullable|integer|min:1|max:'.PHP_INT_MAX,
'since_id' => 'nullable|integer|min:1|max:'.PHP_INT_MAX, 'since_id' => 'nullable|integer|min:1|max:'.PHP_INT_MAX,
'types[]' => 'sometimes|array',
'type' => 'sometimes|string|in:mention,reblog,follow,favourite'
]); ]);
$pid = $request->user()->profile_id; $pid = $request->user()->profile_id;
@ -2078,28 +2096,28 @@ class ApiV1Controller extends Controller
$min = 1; $min = 1;
} }
$types = $request->input('types');
$maxId = null; $maxId = null;
$minId = null; $minId = null;
AccountService::setLastActive($request->user()->id);
if($max) { $res = $max ?
$res = NotificationService::getMaxMastodon($pid, $max, $limit); NotificationService::getMaxMastodon($pid, $max, $limit) :
$ids = NotificationService::getRankedMaxId($pid, $max, $limit); NotificationService::getMinMastodon($pid, $min ?? $since, $limit);
if(!empty($ids)) { $ids = $max ?
$maxId = max($ids); NotificationService::getRankedMaxId($pid, $max, $limit) :
$minId = min($ids); NotificationService::getRankedMinId($pid, $min ?? $since, $limit);
} if(!empty($ids)) {
} else { $maxId = max($ids);
$res = NotificationService::getMinMastodon($pid, $min ?? $since, $limit); $minId = min($ids);
$ids = NotificationService::getRankedMinId($pid, $min ?? $since, $limit);
if(!empty($ids)) {
$maxId = max($ids);
$minId = min($ids);
}
} }
if(empty($res) && !Cache::has('pf:services:notifications:hasSynced:'.$pid)) { if(empty($res)) {
Cache::put('pf:services:notifications:hasSynced:'.$pid, 1, 1209600); if(!Cache::has('pf:services:notifications:hasSynced:'.$pid)) {
NotificationService::warmCache($pid, 400, true); Cache::put('pf:services:notifications:hasSynced:'.$pid, 1, 1209600);
NotificationService::warmCache($pid, 400, true);
}
} }
$baseUrl = config('app.url') . '/api/v1/notifications?limit=' . $limit . '&'; $baseUrl = config('app.url') . '/api/v1/notifications?limit=' . $limit . '&';
@ -2153,6 +2171,7 @@ class ApiV1Controller extends Controller
$inTypes = $includeReblogs ? $inTypes = $includeReblogs ?
['photo', 'photo:album', 'video', 'video:album', 'photo:video:album', 'share'] : ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album', 'share'] :
['photo', 'photo:album', 'video', 'video:album', 'photo:video:album']; ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'];
AccountService::setLastActive($request->user()->id);
if(config('exp.cached_home_timeline')) { if(config('exp.cached_home_timeline')) {
$paddedLimit = $includeReblogs ? $limit + 10 : $limit + 50; $paddedLimit = $includeReblogs ? $limit + 10 : $limit + 50;
@ -2402,6 +2421,7 @@ class ApiV1Controller extends Controller
$remote = $request->has('remote'); $remote = $request->has('remote');
$local = $request->has('local'); $local = $request->has('local');
$filtered = $user ? UserFilterService::filters($user->profile_id) : []; $filtered = $user ? UserFilterService::filters($user->profile_id) : [];
AccountService::setLastActive($user->id);
if($remote && config('instance.timeline.network.cached')) { if($remote && config('instance.timeline.network.cached')) {
Cache::remember('api:v1:timelines:network:cache_check', 10368000, function() { Cache::remember('api:v1:timelines:network:cache_check', 10368000, function() {
@ -2593,7 +2613,7 @@ class ApiV1Controller extends Controller
public function statusById(Request $request, $id) public function statusById(Request $request, $id)
{ {
abort_if(!$request->user(), 403); abort_if(!$request->user(), 403);
AccountService::setLastActive($request->user()->id);
$pid = $request->user()->profile_id; $pid = $request->user()->profile_id;
$res = $request->has(self::PF_API_ENTITY_KEY) ? StatusService::get($id, false) : StatusService::getMastodon($id, false); $res = $request->has(self::PF_API_ENTITY_KEY) ? StatusService::get($id, false) : StatusService::getMastodon($id, false);
@ -2637,6 +2657,7 @@ class ApiV1Controller extends Controller
abort_if(!$request->user(), 403); abort_if(!$request->user(), 403);
$user = $request->user(); $user = $request->user();
AccountService::setLastActive($user->id);
$pid = $user->profile_id; $pid = $user->profile_id;
$status = StatusService::getMastodon($id, false); $status = StatusService::getMastodon($id, false);
@ -3107,7 +3128,7 @@ class ApiV1Controller extends Controller
public function statusDelete(Request $request, $id) public function statusDelete(Request $request, $id)
{ {
abort_if(!$request->user(), 403); abort_if(!$request->user(), 403);
AccountService::setLastActive($request->user()->id);
$status = Status::whereProfileId($request->user()->profile->id) $status = Status::whereProfileId($request->user()->profile->id)
->findOrFail($id); ->findOrFail($id);
@ -3135,6 +3156,7 @@ class ApiV1Controller extends Controller
abort_if(!$request->user(), 403); abort_if(!$request->user(), 403);
$user = $request->user(); $user = $request->user();
AccountService::setLastActive($user->id);
$status = Status::whereScope('public')->findOrFail($id); $status = Status::whereScope('public')->findOrFail($id);
if(intval($status->profile_id) !== intval($user->profile_id)) { if(intval($status->profile_id) !== intval($user->profile_id)) {
@ -3181,6 +3203,7 @@ class ApiV1Controller extends Controller
abort_if(!$request->user(), 403); abort_if(!$request->user(), 403);
$user = $request->user(); $user = $request->user();
AccountService::setLastActive($user->id);
$status = Status::whereScope('public')->findOrFail($id); $status = Status::whereScope('public')->findOrFail($id);
if(intval($status->profile_id) !== intval($user->profile_id)) { if(intval($status->profile_id) !== intval($user->profile_id)) {