From b019c704c256c44ae1b6e0ee2ccbcde0eb6bab64 Mon Sep 17 00:00:00 2001 From: Naomi Ahmed Date: Mon, 26 Dec 2022 03:13:20 +0000 Subject: [PATCH] prevent notifications if the notification contains a note that is muted --- .../backend/src/services/create-notification.ts | 13 ++++++++++++- packages/backend/src/services/note/create.ts | 10 +++++++++- .../backend/src/services/note/reaction/create.ts | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/services/create-notification.ts b/packages/backend/src/services/create-notification.ts index d53a4235b8..646e2a2cb4 100644 --- a/packages/backend/src/services/create-notification.ts +++ b/packages/backend/src/services/create-notification.ts @@ -1,6 +1,6 @@ import { publishMainStream } from '@/services/stream.js'; import { pushNotification } from '@/services/push-notification.js'; -import { Notifications, Mutings, UserProfiles, Users } from '@/models/index.js'; +import { Notifications, Mutings, NoteThreadMutings, UserProfiles, Users } from '@/models/index.js'; import { genId } from '@/misc/gen-id.js'; import { User } from '@/models/entities/user.js'; import { Notification } from '@/models/entities/notification.js'; @@ -19,6 +19,17 @@ export async function createNotification( const isMuted = profile?.mutingNotificationTypes.includes(type); + if (data.note != null) { + const threadMute = await NoteThreadMutings.findOneBy({ + userId: notifieeId, + threadId: data.note.threadId || data.note.id, + }); + + if (threadMute) { + return null; + } + } + // Create notification const notification = await Notifications.insert({ id: genId(), diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts index fa8ba6bf1b..85faa8e871 100644 --- a/packages/backend/src/services/note/create.ts +++ b/packages/backend/src/services/note/create.ts @@ -92,6 +92,7 @@ class NotificationManager { createNotification(x.target, x.reason, { notifierId: this.notifier.id, noteId: this.note.id, + note: this.note, }); } } @@ -394,7 +395,14 @@ export default async (user: { id: User['id']; username: User['username']; host: // Notify if (data.renote.userHost === null) { - nm.push(data.renote.userId, type); + const threadMuted = await NoteThreadMutings.findOneBy({ + userId: data.renote.userId, + threadId: data.renote.threadId || data.renote.id, + }); + + if (!threadMuted) { + nm.push(data.renote.userId, type); + } } // Fetch watchers diff --git a/packages/backend/src/services/note/reaction/create.ts b/packages/backend/src/services/note/reaction/create.ts index 83d302826a..4aca1d043a 100644 --- a/packages/backend/src/services/note/reaction/create.ts +++ b/packages/backend/src/services/note/reaction/create.ts @@ -102,6 +102,7 @@ export default async (user: { id: User['id']; host: User['host']; }, note: Note, if (note.userHost === null) { createNotification(note.userId, 'reaction', { notifierId: user.id, + note: note, noteId: note.id, reaction: reaction, }); @@ -115,6 +116,7 @@ export default async (user: { id: User['id']; host: User['host']; }, note: Note, for (const watcher of watchers) { createNotification(watcher.userId, 'reaction', { notifierId: user.id, + note: note, noteId: note.id, reaction: reaction, });