Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions server/websockets/sessionUsersWebsocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ export function setupSessionUsersWebsocket(httpServer: HttpServer) {
io.to(sessionId).emit('sessionUsersUpdate', users);
const overviewIO = getOverviewIO();
if (overviewIO) {
// Force immediate overview data update
setTimeout(async () => {
try {
const { getOverviewData } = await import('./overviewWebsocket.js');
Expand All @@ -386,13 +385,12 @@ export function setupSessionUsersWebsocket(httpServer: HttpServer) {
if (entry) entry.lastActive = Date.now();
});

// On disconnect, flush active time to cache
socket.on('disconnect', () => {
const entry = userActivity.get(userKey);
if (entry) {
const now = Date.now();
const activeTime = Math.max(0, now - entry.sessionStart - (5 * 60 * 1000));
entry.totalActive += activeTime / 60000;
const remainingActiveTime = Math.max(0, (now - entry.lastActive) / 60000 - 0.1);
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic number 0.1 (6 seconds) is used without explanation. Consider defining this as a named constant (e.g., DISCONNECT_BUFFER_MINUTES) with a comment explaining why this buffer is necessary.

Copilot uses AI. Check for mistakes.
entry.totalActive += remainingActiveTime;
incrementStat(user.userId, 'total_time_controlling_minutes', entry.totalActive);
userActivity.delete(userKey);
}
Expand Down Expand Up @@ -439,17 +437,15 @@ export function setupSessionUsersWebsocket(httpServer: HttpServer) {
return io;
}

// Periodic check (e.g., every minute) to update active time
// Removed incrementStat call to prevent double-counting. Time is now only incremented on disconnect.
setInterval(() => {
for (const [userKey, entry] of userActivity.entries()) {
const now = Date.now();
if (now - entry.lastActive > 5 * 60 * 1000) continue; // Idle, skip
const activeTime = (now - entry.lastActive) / 60000;
entry.totalActive += activeTime;
entry.lastActive = now;
// Increment stat in cache
incrementStat(userKey, 'total_time_controlling_minutes', activeTime);
}
for (const [userKey, entry] of userActivity.entries()) {
const now = Date.now();
if (now - entry.lastActive > 5 * 60 * 1000) continue;
const activeTime = (now - entry.lastActive) / 60000;
entry.totalActive += activeTime;
entry.lastActive = now;
}
}, 60 * 1000);

export function getActiveUsers(): typeof activeUsers {
Expand Down
25 changes: 0 additions & 25 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ export default function Navbar({ sessionId, accessId }: NavbarProps) {
<p className="text-sm font-medium text-white leading-tight flex-1">
{notification.text}
</p>
{/* New: Hide button */}
<button
onClick={() => hideNotification(notification.id)}
className="flex-shrink-0 ml-2 text-white hover:text-gray-300 transition-colors"
Expand Down Expand Up @@ -500,30 +499,6 @@ export default function Navbar({ sessionId, accessId }: NavbarProps) {
}
`}
>
<div className="py-2">
<a
href="/create"
className="block px-6 py-3 text-gray-300 hover:text-white hover:bg-blue-600/20 transition-all duration-200 font-medium"
onClick={() => setIsMenuOpen(false)}
>
Create Session
</a>
<a
href="/sessions"
className="block px-6 py-3 text-gray-300 hover:text-white hover:bg-blue-600/20 transition-all duration-200 font-medium"
onClick={() => setIsMenuOpen(false)}
>
My Sessions
</a>
<a
href="/pfatc"
className="block px-6 py-3 text-gray-300 hover:text-white hover:bg-blue-600/20 transition-all duration-200 font-medium"
onClick={() => setIsMenuOpen(false)}
>
PFATC Flights
</a>
</div>

Comment on lines -503 to -526
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I missing something?

<div className="border-t border-zinc-700/50 p-4">
<CustomUserButton
isMobile={true}
Expand Down
Loading
Loading