From 239a6952f717add53d52c3e701e7362eb1987645 Mon Sep 17 00:00:00 2001 From: taichan Date: Tue, 20 Feb 2024 14:57:20 +0900 Subject: [PATCH] Remove duplication of valid notifier check --- .../entities/NotificationEntityService.ts | 35 ------------------- 1 file changed, 35 deletions(-) diff --git a/packages/backend/src/core/entities/NotificationEntityService.ts b/packages/backend/src/core/entities/NotificationEntityService.ts index f6409914eb62..cbe93fc0c02b 100644 --- a/packages/backend/src/core/entities/NotificationEntityService.ts +++ b/packages/backend/src/core/entities/NotificationEntityService.ts @@ -119,8 +119,6 @@ export class NotificationEntityService implements OnModuleInit { let validNotifications = notifications; - validNotifications = await this.#filterValidNotifier(validNotifications, meId); - const noteIds = validNotifications.map(x => 'noteId' in x ? x.noteId : null).filter(isNotNull); const notes = noteIds.length > 0 ? await this.notesRepository.find({ where: { id: In(noteIds) }, @@ -255,8 +253,6 @@ export class NotificationEntityService implements OnModuleInit { let validNotifications = notifications; - validNotifications = await this.#filterValidNotifier(validNotifications, meId); - const noteIds = validNotifications.map(x => 'noteId' in x ? x.noteId : null).filter(isNotNull); const notes = noteIds.length > 0 ? await this.notesRepository.find({ where: { id: In(noteIds) }, @@ -322,35 +318,4 @@ export class NotificationEntityService implements OnModuleInit { return true; } - - /** - * notifierが存在するか、ミュートされていないか、サスペンドされていないかを複数確認する - */ - async #filterValidNotifier ( - notifications: T[], - meId: MiUser['id'], - ) : Promise { - const [ - userIdsWhoMeMuting, - userMutedInstances, - ] = await Promise.all([ - this.cacheService.userMutingsCache.fetch(meId), - this.cacheService.userProfileCache.fetch(meId).then(p => new Set(p.mutedInstances)), - ]); - - const filteredNotifications = ((await Promise.all(notifications.map(async (notification) => { - if (!('notifierId' in notification)) return notification; - if (userIdsWhoMeMuting.has(notification.notifierId)) return null; - - const notifier = await this.usersRepository.findOneBy({ id: notification.notifierId }); - if (notifier === null) return null; - if (notifier.host && userMutedInstances.has(notifier.host)) return null; - - if (notifier.isSuspended) return null; - - return notification; - }))) as [T|null] ).filter((notification): notification is T => notification !== null); - - return filteredNotifications; - } }