diff --git a/packages/frontend/src/components/SkPatternTest.vue b/packages/frontend/src/components/SkPatternTest.vue index f3bbf723a0..660b5d8a0a 100644 --- a/packages/frontend/src/components/SkPatternTest.vue +++ b/packages/frontend/src/components/SkPatternTest.vue @@ -27,8 +27,8 @@ import { i18n } from '@/i18n'; import MkFolder from '@/components/MkFolder.vue'; import MkButton from '@/components/MkButton.vue'; import MkTextarea from '@/components/MkTextarea.vue'; -import { parseMutes } from '@/utility/parse-mutes'; -import { checkWordMute } from '@/utility/check-word-mute'; +import { parseMutes } from '@/utility/parse-mutes.js'; +import { getMutedWords } from '@/utility/check-word-mute.js'; const props = defineProps<{ mutedWords?: string | null, @@ -45,8 +45,8 @@ function testWordMutes() { try { const mutes = parseMutes(props.mutedWords); - const matches = checkWordMute(testWords.value, null, mutes); - testMatches.value = matches ? matches.join(', ') : ''; + const matches = getMutedWords(mutes, testWords.value); + testMatches.value = matches.join(', '); } catch { // Error is displayed by above function testMatches.value = null; diff --git a/packages/frontend/src/utility/check-word-mute.ts b/packages/frontend/src/utility/check-word-mute.ts index 8301e88fdd..3f363573e7 100644 --- a/packages/frontend/src/utility/check-word-mute.ts +++ b/packages/frontend/src/utility/check-word-mute.ts @@ -128,13 +128,15 @@ function getMutes(note: Misskey.entities.Note, withHardMute: boolean, overrides: function isHardMuted(note: Misskey.entities.Note): boolean { if (!$i?.hardMutedWords.length) return false; - return containsMutedWord($i.hardMutedWords, note); + const inputs = expandNote(note); + return containsMutedWord($i.hardMutedWords, inputs); } function isSoftMuted(note: Misskey.entities.Note): string[] { if (!$i?.mutedWords.length) return []; - return getMutedWords($i.mutedWords, note); + const inputs = expandNote(note); + return getMutedWords($i.mutedWords, inputs); } function isSensitiveMuted(note: Misskey.entities.Note): boolean { @@ -151,7 +153,7 @@ function isSensitiveMuted(note: Misskey.entities.Note): boolean { return tl_withSensitive?.value === false; } -function getMutedWords(mutedWords: (string | string[])[], note: Misskey.entities.Note): string[] { +export function getMutedWords(mutedWords: (string | string[])[], inputs: Iterable): string[] { // Parse mutes const { regexMutes, patternMutes } = parseMutes(mutedWords); @@ -163,7 +165,7 @@ function getMutedWords(mutedWords: (string | string[])[], note: Misskey.entities const matches = new Set(); // Expand notes into searchable test - for (const text of expandNote(note)) { + for (const text of inputs) { for (const pattern of patternMutes) { // Case-sensitive, non-boundary search for backwards compatibility if (pattern.every(word => text.includes(word))) { @@ -182,7 +184,7 @@ function getMutedWords(mutedWords: (string | string[])[], note: Misskey.entities return Array.from(matches); } -function containsMutedWord(mutedWords: (string | string[])[], note: Misskey.entities.Note): boolean { +export function containsMutedWord(mutedWords: (string | string[])[], inputs: Iterable): boolean { // Parse mutes const { regexMutes, patternMutes } = parseMutes(mutedWords); @@ -192,7 +194,7 @@ function containsMutedWord(mutedWords: (string | string[])[], note: Misskey.enti } // Expand notes into searchable test - for (const text of expandNote(note)) { + for (const text of inputs) { for (const pattern of patternMutes) { // Case-sensitive, non-boundary search for backwards compatibility if (pattern.every(word => text.includes(word))) { @@ -208,7 +210,7 @@ function containsMutedWord(mutedWords: (string | string[])[], note: Misskey.enti return false; } -function *expandNote(note: Misskey.entities.Note): Generator { +export function *expandNote(note: Misskey.entities.Note): Generator { if (note.cw) yield note.cw; if (note.text) yield note.text; if (note.files) {