From 846e69fe7b15c2672cdc054b4a071f806f51d767 Mon Sep 17 00:00:00 2001 From: sup39 Date: Fri, 23 Feb 2024 20:26:03 +0900 Subject: [PATCH] fix (backend): apply word mutes in notifications Co-authored-by: naskya --- .../src/server/api/endpoints/notes/mentions.ts | 2 ++ packages/backend/src/services/note/create.ts | 13 ++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/notes/mentions.ts b/packages/backend/src/server/api/endpoints/notes/mentions.ts index 44ee9093..b1eef162 100644 --- a/packages/backend/src/server/api/endpoints/notes/mentions.ts +++ b/packages/backend/src/server/api/endpoints/notes/mentions.ts @@ -7,6 +7,7 @@ import { generateMutedUserQuery } from "@/server/api/common/generate-muted-user- import { makePaginationQuery } from "@/server/api/common/make-pagination-query.js"; import { generateBlockedUserQuery } from "@/server/api/common/generate-block-query.js"; import { generateMutedNoteThreadQuery } from "@/server/api/common/generate-muted-note-thread-query.js"; +import { generateMutedNoteQuery } from "@/server/api/common/generate-muted-note-query.js"; export const meta = { tags: ["notes"], @@ -69,6 +70,7 @@ export default define(meta, paramDef, async (ps, user) => { generateVisibilityQuery(query, user); generateMutedUserQuery(query, user); + generateMutedNoteQuery(query, user); generateMutedNoteThreadQuery(query, user); generateBlockedUserQuery(query, user); diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts index 9beb4e6c..7e8bcabe 100644 --- a/packages/backend/src/services/note/create.ts +++ b/packages/backend/src/services/note/create.ts @@ -887,14 +887,17 @@ async function createMentionedEvents( nm: NotificationManager, ) { for (const u of mentionedUsers.filter((u) => Users.isLocalUser(u))) { - const threadMuted = await NoteThreadMutings.findOneBy({ + const isWordMuted = await MutedNotes.existsBy({ userId: u.id, - threadId: note.threadId || note.id, + noteId: note.id, }); + if (isWordMuted) continue; - if (threadMuted) { - continue; - } + const isThreadMuted = await NoteThreadMutings.existsBy({ + userId: u.id, + threadId: note.threadId ?? note.id, + }); + if (isThreadMuted) continue; // note with "specified" visibility might not be visible to mentioned users try {