From d34f7c7faa2ac51cf2d2b6e88060e66ff695695b Mon Sep 17 00:00:00 2001 From: Johann150 Date: Thu, 4 Apr 2024 00:07:45 +0200 Subject: [PATCH] apply mutes to image descriptions Changelog: Added --- packages/backend/src/misc/check-word-mute.ts | 17 +++++++++++++++-- packages/client/src/scripts/check-word-mute.ts | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/misc/check-word-mute.ts b/packages/backend/src/misc/check-word-mute.ts index 614713d33..0fd2a0805 100644 --- a/packages/backend/src/misc/check-word-mute.ts +++ b/packages/backend/src/misc/check-word-mute.ts @@ -13,11 +13,24 @@ type UserLike = { }; export async function checkWordMute(note: NoteLike, me: UserLike | null | undefined, mutedWords: Array): Promise { - // 自分自身 + // own posts if (me && (note.userId === me.id)) return false; if (mutedWords.length > 0) { - const text = ((note.cw ?? '') + '\n' + (note.text ?? '')).trim(); + const text = [ + note.cw, + note.text, + ...note.files.map(file => file.comment) + ] + .map(x => { + if (x == null || x.trim() == '') { + return null; + } else { + return x.trim(); + } + }) + .filter(x => x != null) + .join('\n'); if (text === '') return false; const textLower = text.toLowerCase(); diff --git a/packages/client/src/scripts/check-word-mute.ts b/packages/client/src/scripts/check-word-mute.ts index bbe86162d..dea8e1e84 100644 --- a/packages/client/src/scripts/check-word-mute.ts +++ b/packages/client/src/scripts/check-word-mute.ts @@ -1,9 +1,22 @@ export function checkWordMute(note: Record, me: Record | null | undefined, mutedWords: Array): boolean { - // 自分自身 + // own posts if (me && (note.userId === me.id)) return false; if (mutedWords.length > 0) { - const text = ((note.cw ?? '') + '\n' + (note.text ?? '')).trim(); + const text = [ + note.cw, + note.text, + ...note.files.map(file => file.comment) + ] + .map(x => { + if (x == null || x.trim() == '') { + return null; + } else { + return x.trim(); + } + }) + .filter(x => x != null) + .join('\n'); if (text === '') return false; const textLower = text.toLowerCase();