From b3428480decee97433efd53dafeb4995fe06f2bb Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Fri, 12 Sep 2025 14:31:13 -0400 Subject: [PATCH] hide mandatory CWs when "uncollapse CWs on notes" is enabled --- .../frontend/src/components/SkMutedNote.vue | 6 ++- .../frontend/src/utility/check-word-mute.ts | 45 ++++++++++++------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/packages/frontend/src/components/SkMutedNote.vue b/packages/frontend/src/components/SkMutedNote.vue index db5b4f2316..5eee592d86 100644 --- a/packages/frontend/src/components/SkMutedNote.vue +++ b/packages/frontend/src/components/SkMutedNote.vue @@ -125,7 +125,11 @@ function expand() { emit('expandMute', props.note); } -const mute = checkMute(computed(() => props.note), computed(() => props.withHardMute)); +const mute = checkMute( + computed(() => props.note), + computed(() => props.withHardMute), + computed(() => prefer.s.uncollapseCW), +); const mutedWords = computed(() => mute.value.softMutedWords?.join(', ')); const isExpanded = computed(() => props.skipMute || expandNote.value || !mute.value.hasMute); diff --git a/packages/frontend/src/utility/check-word-mute.ts b/packages/frontend/src/utility/check-word-mute.ts index a92104a403..a2d4296cad 100644 --- a/packages/frontend/src/utility/check-word-mute.ts +++ b/packages/frontend/src/utility/check-word-mute.ts @@ -85,18 +85,19 @@ function provideMuteOverrides(overrides: Reactive | null) { provide(muteOverridesSymbol, overrides); } -export function checkMute(note: Misskey.entities.Note | ComputedRef, withHardMute?: boolean | ComputedRef): ComputedRef { +export function checkMute(note: Misskey.entities.Note | ComputedRef, withHardMute?: boolean | ComputedRef, uncollapseCW?: boolean | ComputedRef): ComputedRef { // inject() can only be used inside script setup, so it MUST be outside the computed block! const overrides = injectMuteOverrides(); return computed(() => { const _note = unref(note); const _withHardMute = unref(withHardMute) ?? true; - return getMutes(_note, _withHardMute, overrides); + const _uncollapseCW = unref(uncollapseCW) ?? false; + return getMutes(_note, _withHardMute, _uncollapseCW, overrides); }); } -function getMutes(note: Misskey.entities.Note, withHardMute: boolean, overrides: MuteOverrides | null): Mute { +function getMutes(note: Misskey.entities.Note, withHardMute: boolean, uncollapseCW: boolean, overrides: MuteOverrides | null): Mute { const override: Partial = overrides ? deepAssign( {}, note.user.host ? overrides.instance[note.user.host] : undefined, @@ -116,26 +117,36 @@ function getMutes(note: Misskey.entities.Note, withHardMute: boolean, overrides: const instanceSilenced = override.instanceSilenced ?? (note.user.instance?.isSilenced && !bypassSilence) ?? false; const threadMuted = override.threadMuted ?? (!isMe && note.isMutingThread); const noteMuted = override.noteMuted ?? (!isMe && note.isMutingNote); - const noteMandatoryCW = override.noteMandatoryCW !== undefined - ? override.noteMandatoryCW - : (isMe ? null : note.mandatoryCW); - const userMandatoryCW = override.userMandatoryCW !== undefined - ? override.userMandatoryCW - : !bypassSilence - ? note.user.mandatoryCW - : null; - - const instanceMandatoryCW = override.instanceMandatoryCW !== undefined - ? override.instanceMandatoryCW - : (!bypassSilence && note.user.instance) - ? note.user.instance.mandatoryCW - : null; + const noteMandatoryCW = getNoteMandatoryCW(note, isMe, uncollapseCW, override); + const userMandatoryCW = getUserMandatoryCW(note, bypassSilence, uncollapseCW, override); + const instanceMandatoryCW = getInstanceMandatoryCW(note, bypassSilence, uncollapseCW, override); const hasMute = hardMuted || softMutedWords.length > 0 || sensitiveMuted || userSilenced || instanceSilenced || threadMuted || noteMuted || !!noteMandatoryCW || !!userMandatoryCW || !!instanceMandatoryCW; return { hasMute, hardMuted, softMutedWords, sensitiveMuted, userSilenced, instanceSilenced, threadMuted, noteMuted, noteMandatoryCW, userMandatoryCW, instanceMandatoryCW }; } +function getNoteMandatoryCW(note: Misskey.entities.Note, isMe: boolean, uncollapseCW: boolean, override: Partial): string | null { + if (override.noteMandatoryCW !== undefined) return override.noteMandatoryCW; + if (uncollapseCW) return null; + if (isMe) return null; + return note.mandatoryCW ?? null; +} + +function getUserMandatoryCW(note: Misskey.entities.Note, bypassSilence: boolean, uncollapseCW: boolean, override: Partial): string | null { + if (override.userMandatoryCW !== undefined) return override.userMandatoryCW; + if (uncollapseCW) return null; + if (bypassSilence) return null; + return note.user.mandatoryCW ?? null; +} + +function getInstanceMandatoryCW(note: Misskey.entities.Note, bypassSilence: boolean, uncollapseCW: boolean, override: Partial): string | null { + if (override.instanceMandatoryCW !== undefined) return override.instanceMandatoryCW; + if (uncollapseCW) return null; + if (bypassSilence) return null; + return note.user.instance?.mandatoryCW ?? null; +} + function isHardMuted(note: Misskey.entities.Note): boolean { if (!$i?.hardMutedWords.length) return false;