feat: emit real-time messages_read socket event when marking conversation as read
This commit is contained in:
@@ -215,7 +215,23 @@ export class MessagesController {
|
|||||||
@Param('id') conversationId: string,
|
@Param('id') conversationId: string,
|
||||||
@CurrentUser('id') userId: 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
|
|||||||
Reference in New Issue
Block a user