fix SkPatternTest.vue

This commit is contained in:
Hazelnoot 2025-06-29 17:35:52 -04:00
parent 376997cbcc
commit 604f5a5c68
2 changed files with 13 additions and 11 deletions

View file

@ -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;

View file

@ -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>): string[] {
// Parse mutes
const { regexMutes, patternMutes } = parseMutes(mutedWords);
@ -163,7 +165,7 @@ function getMutedWords(mutedWords: (string | string[])[], note: Misskey.entities
const matches = new Set<string>();
// 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<string>): 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<string> {
export function *expandNote(note: Misskey.entities.Note): Generator<string> {
if (note.cw) yield note.cw;
if (note.text) yield note.text;
if (note.files) {