feat: Add an admin endpoint to retrieve the total count of unread support messages.
This commit is contained in:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user