Snapshot of main at 9f39a6e1e (2026-11-02)

This commit is contained in:
Ronald Huynen committed 2026-11-02 10:41:47 +01:00
commit 6ccf1792d7
2580 files changed
+1040202

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
<?php
// 2. Middleware for automatic presence tracking
namespace App\Http\Middleware;
use App\Services\PresenceService;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
class TrackUserPresence
{
protected $presenceService;
public function __construct(PresenceService $presenceService)
{
$this->presenceService = $presenceService;
}
public function handle(Request $request, Closure $next, $guard = null)
{
// If no guard specified, use the active guard from session (defaults to 'web')
// This ensures we only track presence for the currently active profile
$activeGuard = $guard ?? $request->session()->get('active_guard', 'web');
if (auth($activeGuard)->check()) {
$user = auth($activeGuard)->user();
$cacheKey = "presence_last_update_{$activeGuard}_{$user->id}";
$lastUpdate = Cache::get($cacheKey);
if (!$lastUpdate || (int) (now()->diffInSeconds($lastUpdate, true)) > timebank_config('presence_settings.update_interval', 60)) { // Only update using this interval
$this->presenceService->updatePresence($user, $activeGuard);
Cache::put($cacheKey, now(), 300);
}
}
return $next($request);
}
}