feat: Add an admin endpoint to retrieve the total count of unread support messages.

This commit is contained in:
pradeepkumar
2026-03-19 04:19:55 +05:30
parent c3a3df704e
commit 4d5a3fc36d
4 changed files with 73 additions and 6 deletions

View File

@@ -82,7 +82,13 @@ export class MessagesGateway implements OnGatewayConnection, OnGatewayDisconnect
}
this.userSocketMap.get(userId)!.add(client.id);
this.logger.log(`Client connected successfully: ${client.id} (User: ${userId})`);
this.logger.log(`Client connected successfully: ${client.id} (User: ${userId}, Role: ${payload.role})`);
// Auto-join admin users to admin_room for support chat notifications
if (payload.role === 'ADMIN') {
client.join('admin_room');
this.logger.log(`Admin ${userId} joined admin_room`);
}
// Update user online status in background (don't await)
this.messagesService.updateOnlineStatus(userId, true)
@@ -337,6 +343,12 @@ export class MessagesGateway implements OnGatewayConnection, OnGatewayDisconnect
// Broadcast to all clients in the support chat room
this.server.to(`support:${data.chatId}`).emit('support_new_message', message);
// Notify admins about new unread count (for sidebar badge)
if (senderRole !== 'ADMIN') {
const unreadTotal = await this.supportChatService.getAdminUnreadTotal();
this.server.to('admin_room').emit('support_unread_update', { unreadTotal });
}
return { success: true, message };
} catch (error) {
return { error: error.message };