diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index b185ac54..dbf8f611 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -18,6 +18,7 @@ use App\{ Notification, Profile, Status, + User, UserFilter, }; use League\Fractal; @@ -112,20 +113,24 @@ class ApiV1Controller extends Controller { abort_if(!$request->user(), 403); $id = $request->user()->id; - - //$res = Cache::remember('mastoapi:user:account:id:'.$id, now()->addHours(6), function() use($id) { - $profile = Profile::whereNull('status')->whereUserId($id)->firstOrFail(); - $resource = new Fractal\Resource\Item($profile, new AccountTransformer()); - $res = $this->fractal->createData($resource)->toArray(); - $res['source'] = [ - 'privacy' => $profile->is_private ? 'private' : 'public', - 'sensitive' => $profile->cw ? true : false, - 'language' => null, - 'note' => '', - 'fields' => [] - ]; - // return $res; - // }); + $key = 'user:last_active_at:id:'.$id; + $ttl = now()->addMinutes(5); + Cache::remember($key, $ttl, function() use($id) { + $user = User::findOrFail($id); + $user->last_active_at = now(); + $user->save(); + return; + }); + $profile = Profile::whereNull('status')->whereUserId($id)->firstOrFail(); + $resource = new Fractal\Resource\Item($profile, new AccountTransformer()); + $res = $this->fractal->createData($resource)->toArray(); + $res['source'] = [ + 'privacy' => $profile->is_private ? 'private' : 'public', + 'sensitive' => $profile->cw ? true : false, + 'language' => null, + 'note' => '', + 'fields' => [] + ]; return response()->json($res); } diff --git a/app/Http/Controllers/Api/BaseApiController.php b/app/Http/Controllers/Api/BaseApiController.php index b06d4f71..1109ae65 100644 --- a/app/Http/Controllers/Api/BaseApiController.php +++ b/app/Http/Controllers/Api/BaseApiController.php @@ -322,6 +322,13 @@ class BaseApiController extends Controller Auth::logout(); return redirect('/login'); } + $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; + }); $resource = new Fractal\Resource\Item($user->profile, new AccountTransformer()); $res = $this->fractal->createData($resource)->toArray(); return response()->json($res);