From 7753124ec1d1fc40454f59820f5478ad5f28cc56 Mon Sep 17 00:00:00 2001 From: tamaina Date: Wed, 21 Feb 2024 18:36:38 +0000 Subject: [PATCH] filter notes to mark as read --- .../src/core/entities/NotificationEntityService.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/core/entities/NotificationEntityService.ts b/packages/backend/src/core/entities/NotificationEntityService.ts index f5df3d9431..fc8881324b 100644 --- a/packages/backend/src/core/entities/NotificationEntityService.ts +++ b/packages/backend/src/core/entities/NotificationEntityService.ts @@ -24,6 +24,7 @@ import type { UserEntityService } from './UserEntityService.js'; import type { NoteEntityService } from './NoteEntityService.js'; const NOTE_REQUIRED_NOTIFICATION_TYPES = new Set(['note', 'mention', 'reply', 'renote', 'renote:grouped', 'quote', 'reaction', 'reaction:grouped', 'pollEnded'] as (typeof groupedNotificationTypes[number])[]); +const MARK_NOTE_READ_NOTIFICATION_TYPES = new Set(['mention', 'reply', 'quote'] as (typeof groupedNotificationTypes[number])[]); @Injectable() export class NotificationEntityService implements OnModuleInit { @@ -229,7 +230,13 @@ export class NotificationEntityService implements OnModuleInit { if (markNotesAsRead) { try { - trackPromise(this.noteReadService.read(meId, notes)); + const noteIdsToRead = validNotifications.reduce((acc, x) => { + if (MARK_NOTE_READ_NOTIFICATION_TYPES.has(x.type) && 'noteId' in x) { + acc.add(x.noteId); + } + return acc; + }, new Set()); + trackPromise(this.noteReadService.read(meId, notes.filter(x => noteIdsToRead.has(x.id)))); } catch (e) { // console.error('error thrown by NoteReadService.read', e); }