From b38811af7c9952d15054f4aec6f81ea22dd290ca Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 6 Apr 2023 15:09:21 +0900 Subject: [PATCH] fix(backend): fix pack of notification behaviour --- .../src/core/entities/NotificationEntityService.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/core/entities/NotificationEntityService.ts b/packages/backend/src/core/entities/NotificationEntityService.ts index 6b9a9d3320..1948cabad9 100644 --- a/packages/backend/src/core/entities/NotificationEntityService.ts +++ b/packages/backend/src/core/entities/NotificationEntityService.ts @@ -108,7 +108,9 @@ export class NotificationEntityService implements OnModuleInit { ) { if (notifications.length === 0) return []; - const noteIds = notifications.map(x => x.noteId).filter(isNotNull); + let validNotifications = notifications; + + const noteIds = validNotifications.map(x => x.noteId).filter(isNotNull); const notes = noteIds.length > 0 ? await this.notesRepository.find({ where: { id: In(noteIds) }, relations: ['user', 'user.avatar', 'user.banner', 'reply', 'reply.user', 'reply.user.avatar', 'reply.user.banner', 'renote', 'renote.user', 'renote.user.avatar', 'renote.user.banner'], @@ -118,7 +120,9 @@ export class NotificationEntityService implements OnModuleInit { }); const packedNotes = new Map(packedNotesArray.map(p => [p.id, p])); - const userIds = notifications.map(x => x.notifierId).filter(isNotNull); + validNotifications = validNotifications.filter(x => x.noteId == null || packedNotes.has(x.noteId)); + + const userIds = validNotifications.map(x => x.notifierId).filter(isNotNull); const users = userIds.length > 0 ? await this.usersRepository.find({ where: { id: In(userIds) }, relations: ['avatar', 'banner'], @@ -128,7 +132,7 @@ export class NotificationEntityService implements OnModuleInit { }); const packedUsers = new Map(packedUsersArray.map(p => [p.id, p])); - return await Promise.all(notifications.map(x => this.pack(x, meId, {}, { + return await Promise.all(validNotifications.map(x => this.pack(x, meId, {}, { packedNotes, packedUsers, })));