From ae637ec85bbd0aee95955ffb7e892de2a53573ff Mon Sep 17 00:00:00 2001 From: naskya Date: Tue, 17 Oct 2023 07:34:19 +0900 Subject: [PATCH] fix: consider hard mutes in antennas --- .../backend/src/misc/check-hit-antenna.ts | 22 ++++++++++++++----- packages/backend/src/misc/check-word-mute.ts | 4 ++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/misc/check-hit-antenna.ts b/packages/backend/src/misc/check-hit-antenna.ts index 3ec019273f..270a58cf13 100644 --- a/packages/backend/src/misc/check-hit-antenna.ts +++ b/packages/backend/src/misc/check-hit-antenna.ts @@ -1,11 +1,12 @@ import type { Antenna } from "@/models/entities/antenna.js"; import type { Note } from "@/models/entities/note.js"; import type { User } from "@/models/entities/user.js"; -import { Blockings } from "@/models/index.js"; +import { Blockings, UserProfiles } from "@/models/index.js"; import { getFullApAccount } from "./convert-host.js"; import * as Acct from "@/misc/acct.js"; import type { Packed } from "./schema.js"; import { Cache } from "./cache.js"; +import { getWordHardMute } from "./check-word-mute.js"; const blockingCache = new Cache("blocking", 60 * 5); @@ -16,6 +17,10 @@ export async function checkHitAntenna( ): Promise { if (note.visibility === "specified") return false; if (note.visibility === "home") return false; + if (!antenna.withReplies && note.replyId != null) return false; + if (antenna.withFile) { + if (note.fileIds && note.fileIds.length === 0) return false; + } // アンテナ作成者がノート作成者にブロックされていたらスキップ const blockings = await blockingCache.fetch(noteUser.id, () => @@ -25,8 +30,6 @@ export async function checkHitAntenna( ); if (blockings.some((blocking) => blocking === antenna.userId)) return false; - if (!antenna.withReplies && note.replyId != null) return false; - if (antenna.src === "users") { const accts = antenna.users.map((x) => { const { username, host } = Acct.parse(x); @@ -85,9 +88,16 @@ export async function checkHitAntenna( if (matched) return false; } - if (antenna.withFile) { - if (note.fileIds && note.fileIds.length === 0) return false; - } + if ( + await getWordHardMute( + note, + antenna.userId, + ( + await UserProfiles.findOneBy({ userId: antenna.userId }) + )?.mutedWords, + ) + ) + return false; // TODO: eval expression diff --git a/packages/backend/src/misc/check-word-mute.ts b/packages/backend/src/misc/check-word-mute.ts index 88f3714ab9..5686aef2f7 100644 --- a/packages/backend/src/misc/check-word-mute.ts +++ b/packages/backend/src/misc/check-word-mute.ts @@ -57,9 +57,9 @@ function checkWordMute( export async function getWordHardMute( note: NoteLike, meId: string | null | undefined, - mutedWords: Array, + mutedWords?: Array, ): Promise { - if (note.userId === meId) return false; + if (note.userId === meId || mutedWords == null) return false; if (mutedWords.length > 0) { return (