Merge pull request 'fix: TypeError in word mutes' (#10168) from naskya/calckey:fix/alt-text-mutes-undefined into develop

Reviewed-on: https://codeberg.org/calckey/calckey/pulls/10168
This commit is contained in:
Kainoa Kanter 2023-05-20 23:41:47 +00:00
commit 34df8dde40
2 changed files with 11 additions and 7 deletions

View file

@ -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) {

View file

@ -10,9 +10,11 @@ function checkWordMute(
note: NoteLike,
mutedWords: Array<string | string[]>,
): 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: [] };