fix: standardize message timestamps to ISO strings and update delivery status in real-time events
This commit is contained in:
@@ -226,7 +226,7 @@ export class MessagesController {
|
||||
const readEvent = {
|
||||
conversationId,
|
||||
readBy: userId,
|
||||
readAt: new Date(),
|
||||
readAt: new Date().toISOString(),
|
||||
};
|
||||
this.messagesGateway.sendToUser(otherUserId, 'messages_read', readEvent);
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ export class MessagesGateway implements OnGatewayConnection, OnGatewayDisconnect
|
||||
const deliveredEvent = {
|
||||
messageIds: result.messageIds,
|
||||
conversationId: result.conversationId,
|
||||
deliveredAt: result.deliveredAt,
|
||||
deliveredAt: result.deliveredAt.toISOString(),
|
||||
};
|
||||
this.sendToUser(result.senderId, 'message_delivered', deliveredEvent);
|
||||
}
|
||||
@@ -228,7 +228,7 @@ export class MessagesGateway implements OnGatewayConnection, OnGatewayDisconnect
|
||||
}
|
||||
|
||||
try {
|
||||
const message = await this.messagesService.createMessage(
|
||||
let message = await this.messagesService.createMessage(
|
||||
data.conversationId,
|
||||
client.userId,
|
||||
data.message,
|
||||
@@ -246,13 +246,17 @@ export class MessagesGateway implements OnGatewayConnection, OnGatewayDisconnect
|
||||
|
||||
// Auto-mark as DELIVERED if recipient is online
|
||||
if (this.isUserOnline(otherUserId)) {
|
||||
const deliveredAt = new Date().toISOString();
|
||||
await this.messagesService.markMessageDelivered(message.id);
|
||||
// Update message object so sender gets correct status in callback
|
||||
message = { ...message, status: 'DELIVERED' as any, deliveredAt } as any;
|
||||
|
||||
const deliveredEvent = {
|
||||
messageId: message.id,
|
||||
conversationId: data.conversationId,
|
||||
deliveredAt: new Date(),
|
||||
deliveredAt,
|
||||
};
|
||||
// Notify sender that message was delivered
|
||||
// Also send event for clients that might have the old status cached
|
||||
this.sendToUser(client.userId, 'message_delivered', deliveredEvent);
|
||||
}
|
||||
}
|
||||
@@ -327,7 +331,7 @@ export class MessagesGateway implements OnGatewayConnection, OnGatewayDisconnect
|
||||
const readEvent = {
|
||||
conversationId: data.conversationId,
|
||||
readBy: client.userId,
|
||||
readAt: new Date(),
|
||||
readAt: new Date().toISOString(),
|
||||
};
|
||||
|
||||
// Notify via room (for clients viewing this conversation)
|
||||
|
||||
Reference in New Issue
Block a user