From 4d87266d130ab6f4e2142d1eed2ff3058526e5d6 Mon Sep 17 00:00:00 2001 From: naskya Date: Sun, 21 May 2023 05:34:39 +0900 Subject: [PATCH] files may be undefined --- packages/backend/src/misc/check-word-mute.ts | 10 ++++++---- packages/client/src/scripts/check-word-mute.ts | 8 +++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/misc/check-word-mute.ts b/packages/backend/src/misc/check-word-mute.ts index 61047de19..8c7d95086 100644 --- a/packages/backend/src/misc/check-word-mute.ts +++ b/packages/backend/src/misc/check-word-mute.ts @@ -5,7 +5,7 @@ import type { User } from "@/models/entities/user.js"; type NoteLike = { userId: Note["userId"]; text: Note["text"]; - files: Note["files"]; + files?: Note["files"]; cw?: Note["cw"]; }; @@ -19,9 +19,11 @@ function checkWordMute( ): boolean { if (note == null) return false; - const text = `${note.cw ?? ""} ${note.text ?? ""} ${note.files - .map((f) => f.comment ?? "") - .join(" ")}`.trim(); + let text = `${note.cw ?? ""} ${note.text ?? ""}`; + if (note.files != null) + text += ` ${note.files.map((f) => f.comment ?? "").join(" ")}`; + text = text.trim(); + if (text === "") return false; for (const mutePattern of mutedWords) { diff --git a/packages/client/src/scripts/check-word-mute.ts b/packages/client/src/scripts/check-word-mute.ts index c2943d6ae..f789d0cd1 100644 --- a/packages/client/src/scripts/check-word-mute.ts +++ b/packages/client/src/scripts/check-word-mute.ts @@ -10,9 +10,11 @@ function checkWordMute( note: NoteLike, mutedWords: Array, ): Muted { - const text = `${note.cw ?? ""} ${note.text ?? ""} ${note.files - .map((f) => f.comment ?? "") - .join(" ")}`.trim(); + let text = `${note.cw ?? ""} ${note.text ?? ""}`; + if (note.files != null) + text += ` ${note.files.map((f) => f.comment ?? "").join(" ")}`; + text = text.trim(); + if (text === "") return NotMuted; let result = { muted: false, matched: [] };