fix(chat): real-time active users list updates
Fixed issue where active users list in event chat did not update in real-time when new users joined. Users had to refresh the page to see newly joined participants. Root Cause: - getAllDisplayUsers() used checkedInUsers (loaded once from API) as base list, with activeUsers (Socket.IO real-time) only for isOnline flag - When new user joined chat, they appeared in activeUsers but not in checkedInUsers, so they were not displayed Solution: - Rewrote getAllDisplayUsers() to prioritize activeUsers (real-time data) - Merges activeUsers (online) with checkedInUsers (offline checked-in users) - Uses Socket.IO data as source of truth for online users - Enriches with database data when available (firstName, lastName, etc) - Sorts online users first, offline second Changes: - EventChatPage.jsx: Rewrote getAllDisplayUsers() to merge activeUsers with checkedInUsers, prioritizing real-time Socket.IO data - useEventChat.js: Added debug logging for active_users events - socket/index.js: Added debug logging for active_users emissions Testing: - User A in chat sees User B appear immediately when B joins - No page refresh required - Online/offline status updates in real-time
This commit is contained in:
@@ -143,12 +143,14 @@ const useEventChat = (slug, userId, event, messagesContainerRef) => {
|
||||
|
||||
// Receive active users list
|
||||
socket.on('active_users', (users) => {
|
||||
console.log('📡 Received active_users event:', users);
|
||||
// Filter out duplicates and current user
|
||||
const uniqueUsers = users
|
||||
.filter((u, index, self) =>
|
||||
index === self.findIndex((t) => t.userId === u.userId)
|
||||
)
|
||||
.filter((u) => u.userId !== userId);
|
||||
console.log('👥 Updating active users:', uniqueUsers);
|
||||
setActiveUsers(uniqueUsers);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user