diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-05-12 23:28:55 -0400 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-05-12 23:28:55 -0400 |
| commit | b52db71e1894e25cebfafc782d2cec86705e2cbb (patch) | |
| tree | c3444a49a9507403a5e6cbd0a7f1a8fd4a0e10d9 /packages/frontend/src/utility | |
| parent | simplify access to showSoftWordMutedWord (diff) | |
| download | sharkey-b52db71e1894e25cebfafc782d2cec86705e2cbb.tar.gz sharkey-b52db71e1894e25cebfafc782d2cec86705e2cbb.tar.bz2 sharkey-b52db71e1894e25cebfafc782d2cec86705e2cbb.zip | |
factor out shared word mute logic
Diffstat (limited to 'packages/frontend/src/utility')
| -rw-r--r-- | packages/frontend/src/utility/check-word-mute.ts | 36 |
1 files changed, 36 insertions, 0 deletions
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<string | string[]> | undefined | null, checkOnly: true): boolean; +function checkMute(noteToCheck: Misskey.entities.Note, mutedWords: Array<string | string[]> | undefined | null, checkOnly: false): Array<string | string[]> | false | 'sensitiveMute'; +*/ +export function checkMute(noteToCheck: Misskey.entities.Note, mutedWords: Array<string | string[]> | undefined | null, checkOnly = false): Array<string | string[]> | 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<boolean>('inTimeline', false); + const tl_withSensitive = inject<Ref<boolean> | 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<string | string[]>): Array<string | string[]> | false { // 自分自身 |