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 = {
|
const readEvent = {
|
||||||
conversationId,
|
conversationId,
|
||||||
readBy: userId,
|
readBy: userId,
|
||||||
readAt: new Date(),
|
readAt: new Date().toISOString(),
|
||||||
};
|
};
|
||||||
this.messagesGateway.sendToUser(otherUserId, 'messages_read', readEvent);
|
this.messagesGateway.sendToUser(otherUserId, 'messages_read', readEvent);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ export class MessagesGateway implements OnGatewayConnection, OnGatewayDisconnect
|
|||||||
const deliveredEvent = {
|
const deliveredEvent = {
|
||||||
messageIds: result.messageIds,
|
messageIds: result.messageIds,
|
||||||
conversationId: result.conversationId,
|
conversationId: result.conversationId,
|
||||||
deliveredAt: result.deliveredAt,
|
deliveredAt: result.deliveredAt.toISOString(),
|
||||||
};
|
};
|
||||||
this.sendToUser(result.senderId, 'message_delivered', deliveredEvent);
|
this.sendToUser(result.senderId, 'message_delivered', deliveredEvent);
|
||||||
}
|
}
|
||||||
@@ -228,7 +228,7 @@ export class MessagesGateway implements OnGatewayConnection, OnGatewayDisconnect
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const message = await this.messagesService.createMessage(
|
let message = await this.messagesService.createMessage(
|
||||||
data.conversationId,
|
data.conversationId,
|
||||||
client.userId,
|
client.userId,
|
||||||
data.message,
|
data.message,
|
||||||
@@ -246,13 +246,17 @@ export class MessagesGateway implements OnGatewayConnection, OnGatewayDisconnect
|
|||||||
|
|
||||||
// Auto-mark as DELIVERED if recipient is online
|
// Auto-mark as DELIVERED if recipient is online
|
||||||
if (this.isUserOnline(otherUserId)) {
|
if (this.isUserOnline(otherUserId)) {
|
||||||
|
const deliveredAt = new Date().toISOString();
|
||||||
await this.messagesService.markMessageDelivered(message.id);
|
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 = {
|
const deliveredEvent = {
|
||||||
messageId: message.id,
|
messageId: message.id,
|
||||||
conversationId: data.conversationId,
|
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);
|
this.sendToUser(client.userId, 'message_delivered', deliveredEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -327,7 +331,7 @@ export class MessagesGateway implements OnGatewayConnection, OnGatewayDisconnect
|
|||||||
const readEvent = {
|
const readEvent = {
|
||||||
conversationId: data.conversationId,
|
conversationId: data.conversationId,
|
||||||
readBy: client.userId,
|
readBy: client.userId,
|
||||||
readAt: new Date(),
|
readAt: new Date().toISOString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Notify via room (for clients viewing this conversation)
|
// Notify via room (for clients viewing this conversation)
|
||||||
|
|||||||
Reference in New Issue
Block a user