Improve realtime chat delivery and notification events
فشلت بعض الفحوصات
Deploy To Ghaymah / deploy (push) Has been cancelled

هذا الالتزام موجود في:
boutmoun123
2026-06-07 14:57:36 +03:00
الأصل 22550055d3
التزام c93296ba9d
11 ملفات معدلة مع 462 إضافات و38 حذوفات

عرض الملف

@@ -212,17 +212,60 @@ export class ChatService {
}
}
async markMessageSeen(currentUserId: string, messageId: string) {
async markMessageSeen(currentUserId: string, messageId: string, conversationId?: string) {
if (!Types.ObjectId.isValid(messageId)) {
throw new BadRequestException('Invalid message id');
}
if (conversationId && !Types.ObjectId.isValid(conversationId)) {
throw new BadRequestException('Invalid conversation id');
}
const message = await this.chatRepository.findMessageById(messageId);
if (!message) {
throw new NotFoundException('Message not found');
}
if (conversationId && message.conversationId.toString() !== conversationId) {
throw new BadRequestException('Message must belong to the conversation');
}
await this.assertConversationMember(currentUserId, message.conversationId.toString());
await this.chatRepository.markMessageSeen(message.id, currentUserId);
await this.chatRepository.clearConversationUnreadForUser(message.conversationId.toString(), currentUserId);
const seenAt = new Date();
return { success: true };
return {
success: true,
conversationId: message.conversationId.toString(),
messageId: message.id,
userId: currentUserId,
seenAt: seenAt.toISOString(),
};
}
async markMessageDelivered(currentUserId: string, conversationId: string, messageId: string) {
const conversation = await this.assertConversationMember(currentUserId, conversationId);
if (!Types.ObjectId.isValid(messageId)) {
throw new BadRequestException('Invalid message id');
}
const message = await this.chatRepository.findMessageById(messageId);
if (!message || message.conversationId.toString() !== conversation.id) {
throw new BadRequestException('Message must belong to the conversation');
}
if (message.senderId.toString() === currentUserId) {
throw new BadRequestException('Sender cannot mark own message delivered');
}
const deliveredAt = new Date();
await this.chatRepository.markMessageDelivered(message.id, currentUserId, deliveredAt);
return {
conversationId: conversation.id,
messageId: message.id,
userId: currentUserId,
deliveredAt: deliveredAt.toISOString(),
};
}
async unsendMessage(currentUserId: string, messageId: string) {