Use original (Misskey's) implementation for hard mutes as muted reason isn't needed
This commit is contained in:
parent
ffea68ad8d
commit
7113735212
|
@ -25,39 +25,30 @@ function checkWordMute(
|
||||||
const text = ((note.cw ?? "") + " " + (note.text ?? "")).trim();
|
const text = ((note.cw ?? "") + " " + (note.text ?? "")).trim();
|
||||||
if (text === "") return false;
|
if (text === "") return false;
|
||||||
|
|
||||||
for (const mutePattern of mutedWords) {
|
const matched = mutedWords.some(filter => {
|
||||||
let mute: RE2;
|
if (Array.isArray(filter)) {
|
||||||
let matched: string[];
|
return filter.every(keyword => text.includes(keyword));
|
||||||
if (Array.isArray(mutePattern)) {
|
|
||||||
matched = mutePattern.filter((keyword) => keyword !== "");
|
|
||||||
|
|
||||||
if (matched.length === 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
mute = new RE2(
|
|
||||||
`\\b${matched.map(escapeRegExp).join("\\b.*\\b")}\\b`,
|
|
||||||
"g",
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
const regexp = mutePattern.match(/^\/(.+)\/(.*)$/);
|
// represents RegExp
|
||||||
|
const regexp = filter.match(/^\/(.+)\/(.*)$/);
|
||||||
|
|
||||||
// This should never happen due to input sanitisation.
|
// This should never happen due to input sanitisation.
|
||||||
if (!regexp) {
|
if (!regexp) {
|
||||||
console.warn(`Found invalid regex in word mutes: ${mutePattern}`);
|
console.warn(`Found invalid regex in word mutes: ${mutePattern}`);
|
||||||
continue;
|
return false;
|
||||||
}
|
|
||||||
mute = new RE2(regexp[1], regexp[2]);
|
|
||||||
matched = [mutePattern];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (mute.test(text)) return true;
|
return new RE2(regexp[1], regexp[2]).test(text);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// This should never happen due to input sanitisation.
|
// This should never happen due to input sanitisation.
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return matched;
|
||||||
|
}
|
||||||
|
|
||||||
export async function getWordHardMute(
|
export async function getWordHardMute(
|
||||||
note: NoteLike,
|
note: NoteLike,
|
||||||
|
|
Loading…
Reference in New Issue