From 475bc9e2513456e5b282cce239e194c82ea3e42d Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Tue, 31 Mar 2026 19:28:48 +0530 Subject: [PATCH] feat: emit real-time messages_read socket event when marking conversation as read --- src/messages/messages.controller.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/messages/messages.controller.ts b/src/messages/messages.controller.ts index a387b96..90cf02a 100644 --- a/src/messages/messages.controller.ts +++ b/src/messages/messages.controller.ts @@ -215,7 +215,23 @@ export class MessagesController { @Param('id') conversationId: string, @CurrentUser('id') userId: string, ) { - return this.messagesService.markMessagesAsRead(conversationId, userId); + const result = await this.messagesService.markMessagesAsRead(conversationId, userId); + + // Emit socket event so sender gets real-time blue tick + const participants = await this.messagesService.getConversationParticipants(conversationId); + if (participants) { + const otherUserId = userId === participants.userId + ? participants.agentUserId + : participants.userId; + const readEvent = { + conversationId, + readBy: userId, + readAt: new Date(), + }; + this.messagesGateway.sendToUser(otherUserId, 'messages_read', readEvent); + } + + return result; } // ==========================================