Fix chat unread counter map updates
فشلت بعض الفحوصات
Deploy To Ghaymah / deploy (push) Has been cancelled
فشلت بعض الفحوصات
Deploy To Ghaymah / deploy (push) Has been cancelled
هذا الالتزام موجود في:
@@ -82,9 +82,11 @@ export class ChatService {
|
||||
]);
|
||||
|
||||
const mappedItems = items.map((conversation) => {
|
||||
const unreadMap = (conversation.unreadCountByUser as unknown as Record<string, number>) ?? {};
|
||||
const conversationObject = conversation.toObject();
|
||||
const unreadMap = this.normalizeUnreadCountByUser(conversationObject.unreadCountByUser);
|
||||
return {
|
||||
...conversation.toObject(),
|
||||
...conversationObject,
|
||||
unreadCountByUser: unreadMap,
|
||||
unreadCount: unreadMap[currentUserId] ?? 0,
|
||||
lastMessageAt: conversation.lastMessageAt ?? null,
|
||||
};
|
||||
@@ -104,6 +106,10 @@ export class ChatService {
|
||||
}
|
||||
|
||||
async getMessages(currentUserId: string, conversationId: string, query: MessageQueryDto) {
|
||||
if (!conversationId?.trim()) {
|
||||
throw new BadRequestException('conversationId is required');
|
||||
}
|
||||
|
||||
const conversation = await this.assertConversationMember(currentUserId, conversationId);
|
||||
const page = query.page ?? 1;
|
||||
const limit = query.limit ?? 20;
|
||||
@@ -326,6 +332,28 @@ export class ChatService {
|
||||
}
|
||||
}
|
||||
|
||||
private normalizeUnreadCountByUser(value: unknown): Record<string, number> {
|
||||
if (!value) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (value instanceof Map) {
|
||||
return Object.fromEntries(
|
||||
Array.from(value.entries()).map(([key, count]) => [key.toString(), Number(count) || 0]),
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof value === 'object') {
|
||||
return Object.fromEntries(
|
||||
Object.entries(value as Record<string, unknown>)
|
||||
.filter(([key]) => !key.startsWith('$__') && key !== '$isMongooseMap')
|
||||
.map(([key, count]) => [key, Number(count) || 0]),
|
||||
);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
private async resolveReplyToMessageId(replyToMessageId: string | undefined, conversationId: string) {
|
||||
if (!replyToMessageId) {
|
||||
return null;
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم