From b52db71e1894e25cebfafc782d2cec86705e2cbb Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Mon, 12 May 2025 23:28:55 -0400 Subject: factor out shared word mute logic --- packages/frontend/src/utility/check-word-mute.ts | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'packages/frontend/src/utility') diff --git a/packages/frontend/src/utility/check-word-mute.ts b/packages/frontend/src/utility/check-word-mute.ts index 2d8486760d..dc36ea1906 100644 --- a/packages/frontend/src/utility/check-word-mute.ts +++ b/packages/frontend/src/utility/check-word-mute.ts @@ -3,6 +3,42 @@ * SPDX-License-Identifier: AGPL-3.0-only */ import * as Misskey from 'misskey-js'; +import { inject, ref } from 'vue'; +import type { Ref } from 'vue'; +import { $i } from '@/i'; + +export function checkMutes(noteToCheck: Misskey.entities.Note, withHardMute = false) { + const muted = ref(checkMute(noteToCheck, $i?.mutedWords)); + const hardMuted = ref(withHardMute && checkMute(noteToCheck, $i?.hardMutedWords, true)); + return { muted, hardMuted }; +} + +/* Overload FunctionにLintが対応していないのでコメントアウト +function checkMute(noteToCheck: Misskey.entities.Note, mutedWords: Array | undefined | null, checkOnly: true): boolean; +function checkMute(noteToCheck: Misskey.entities.Note, mutedWords: Array | undefined | null, checkOnly: false): Array | false | 'sensitiveMute'; +*/ +export function checkMute(noteToCheck: Misskey.entities.Note, mutedWords: Array | undefined | null, checkOnly = false): Array | false | 'sensitiveMute' { + if (mutedWords != null) { + const result = checkWordMute(noteToCheck, $i, mutedWords); + if (Array.isArray(result)) return result; + + const replyResult = noteToCheck.reply && checkWordMute(noteToCheck.reply, $i, mutedWords); + if (Array.isArray(replyResult)) return replyResult; + + const renoteResult = noteToCheck.renote && checkWordMute(noteToCheck.renote, $i, mutedWords); + if (Array.isArray(renoteResult)) return renoteResult; + } + + if (checkOnly) return false; + + const inTimeline = inject('inTimeline', false); + const tl_withSensitive = inject | null>('tl_withSensitive', null); + if (inTimeline && tl_withSensitive?.value === false && noteToCheck.files?.some((v) => v.isSensitive)) { + return 'sensitiveMute'; + } + + return false; +} export function checkWordMute(note: string | Misskey.entities.Note, me: Misskey.entities.UserLite | null | undefined, mutedWords: Array): Array | false { // 自分自身 -- cgit v1.2.3-freya