diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2022-02-11 17:58:04 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2022-02-11 17:58:04 +0900 |
| commit | 1ce8da66c2a38fea9bf7aa314717412539fbab6d (patch) | |
| tree | 3c02cc6ec9ce2ee8313943240e7d423573462244 /packages/client/src/scripts | |
| parent | Merge branch 'develop' (diff) | |
| parent | 12.106.0 (diff) | |
| download | misskey-1ce8da66c2a38fea9bf7aa314717412539fbab6d.tar.gz misskey-1ce8da66c2a38fea9bf7aa314717412539fbab6d.tar.bz2 misskey-1ce8da66c2a38fea9bf7aa314717412539fbab6d.zip | |
Merge branch 'develop'
Diffstat (limited to 'packages/client/src/scripts')
| -rw-r--r-- | packages/client/src/scripts/check-word-mute.ts | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/packages/client/src/scripts/check-word-mute.ts b/packages/client/src/scripts/check-word-mute.ts index 55637bb3b3..74e2581863 100644 --- a/packages/client/src/scripts/check-word-mute.ts +++ b/packages/client/src/scripts/check-word-mute.ts @@ -1,23 +1,28 @@ -export function checkWordMute(note: Record<string, any>, me: Record<string, any> | null | undefined, mutedWords: string[][]): boolean { +export function checkWordMute(note: Record<string, any>, me: Record<string, any> | null | undefined, mutedWords: Array<string | string[]>): boolean { // 自分自身 if (me && (note.userId === me.id)) return false; - const words = mutedWords - // Clean up - .map(xs => xs.filter(x => x !== '')) - .filter(xs => xs.length > 0); - - if (words.length > 0) { + if (mutedWords.length > 0) { if (note.text == null) return false; - const matched = words.some(and => - and.every(keyword => { - const regexp = keyword.match(/^\/(.+)\/(.*)$/); - if (regexp) { + const matched = mutedWords.some(filter => { + if (Array.isArray(filter)) { + return filter.every(keyword => note.text!.includes(keyword)); + } else { + // represents RegExp + const regexp = filter.match(/^\/(.+)\/(.*)$/); + + // This should never happen due to input sanitisation. + if (!regexp) return false; + + try { return new RegExp(regexp[1], regexp[2]).test(note.text!); + } catch (err) { + // This should never happen due to input sanitisation. + return false; } - return note.text!.includes(keyword); - })); + } + }); if (matched) return true; } |