enhance: word mute checks CW (#8873)
This commit is contained in:
parent
d1e151172b
commit
ecdaeea94f
|
@ -16,11 +16,13 @@ export async function checkWordMute(note: NoteLike, me: UserLike | null | undefi
|
||||||
if (me && (note.userId === me.id)) return false;
|
if (me && (note.userId === me.id)) return false;
|
||||||
|
|
||||||
if (mutedWords.length > 0) {
|
if (mutedWords.length > 0) {
|
||||||
if (note.text == null) return false;
|
const text = ((note.cw ?? '') + '\n' + (note.text ?? '')).trim();
|
||||||
|
|
||||||
|
if (text == '') return false;
|
||||||
|
|
||||||
const matched = mutedWords.some(filter => {
|
const matched = mutedWords.some(filter => {
|
||||||
if (Array.isArray(filter)) {
|
if (Array.isArray(filter)) {
|
||||||
return filter.every(keyword => note.text!.includes(keyword));
|
return filter.every(keyword => text.includes(keyword));
|
||||||
} else {
|
} else {
|
||||||
// represents RegExp
|
// represents RegExp
|
||||||
const regexp = filter.match(/^\/(.+)\/(.*)$/);
|
const regexp = filter.match(/^\/(.+)\/(.*)$/);
|
||||||
|
@ -29,7 +31,7 @@ export async function checkWordMute(note: NoteLike, me: UserLike | null | undefi
|
||||||
if (!regexp) return false;
|
if (!regexp) return false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new RE2(regexp[1], regexp[2]).test(note.text!);
|
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;
|
||||||
|
|
|
@ -3,7 +3,9 @@ export function checkWordMute(note: Record<string, any>, me: Record<string, any>
|
||||||
if (me && (note.userId === me.id)) return false;
|
if (me && (note.userId === me.id)) return false;
|
||||||
|
|
||||||
if (mutedWords.length > 0) {
|
if (mutedWords.length > 0) {
|
||||||
if (note.text == null) return false;
|
const text = ((note.cw ?? '') + '\n' + (note.text ?? '')).trim();
|
||||||
|
|
||||||
|
if (text == '') return false;
|
||||||
|
|
||||||
const matched = mutedWords.some(filter => {
|
const matched = mutedWords.some(filter => {
|
||||||
if (Array.isArray(filter)) {
|
if (Array.isArray(filter)) {
|
||||||
|
@ -11,7 +13,7 @@ export function checkWordMute(note: Record<string, any>, me: Record<string, any>
|
||||||
const filteredFilter = filter.filter(keyword => keyword !== '');
|
const filteredFilter = filter.filter(keyword => keyword !== '');
|
||||||
if (filteredFilter.length === 0) return false;
|
if (filteredFilter.length === 0) return false;
|
||||||
|
|
||||||
return filteredFilter.every(keyword => note.text!.includes(keyword));
|
return filteredFilter.every(keyword => text.includes(keyword));
|
||||||
} else {
|
} else {
|
||||||
// represents RegExp
|
// represents RegExp
|
||||||
const regexp = filter.match(/^\/(.+)\/(.*)$/);
|
const regexp = filter.match(/^\/(.+)\/(.*)$/);
|
||||||
|
@ -20,7 +22,7 @@ export function checkWordMute(note: Record<string, any>, me: Record<string, any>
|
||||||
if (!regexp) return false;
|
if (!regexp) return false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new RegExp(regexp[1], regexp[2]).test(note.text!);
|
return new RegExp(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;
|
||||||
|
|
Loading…
Reference in New Issue