From 72ef92f0d62828754702cd00e26ad873adb4652f Mon Sep 17 00:00:00 2001
From: taichan <40626578+tai-cha@users.noreply.github.com>
Date: Tue, 14 Jan 2025 13:07:38 +0000
Subject: [PATCH] =?UTF-8?q?perf:=20filter=20->=20find=E3=81=AB=E5=A4=89?=
=?UTF-8?q?=E6=9B=B4=E3=81=97=E3=81=A6=E6=9C=80=E5=88=9D=E3=81=AE=E4=B8=80?=
=?UTF-8?q?=E5=80=8B=E3=81=AE=E3=81=BF=E3=82=92=E8=A1=A8=E7=A4=BA=E3=81=99?=
=?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
packages/frontend/src/components/MkNote.vue | 12 ++++++------
packages/frontend/src/scripts/check-word-mute.ts | 6 +++---
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/packages/frontend/src/components/MkNote.vue b/packages/frontend/src/components/MkNote.vue
index 4c26444b35..ec4f181941 100644
--- a/packages/frontend/src/components/MkNote.vue
+++ b/packages/frontend/src/components/MkNote.vue
@@ -164,7 +164,7 @@ SPDX-License-Identifier: AGPL-3.0-only
- {{ Array.isArray(muted) ? muted.map(words => Array.isArray(words) ? words.join() : words).slice(0, 3).join(' ') : muted }}
+ {{ Array.isArray(muted) ? muted.join(' ') : muted }}
@@ -301,19 +301,19 @@ const pleaseLoginContext = computed(() => ({
/* Overload FunctionにLintが対応していないのでコメントアウト
function checkMute(noteToCheck: Misskey.entities.Note, mutedWords: Array | undefined | null, checkOnly: true): boolean;
-function checkMute(noteToCheck: Misskey.entities.Note, mutedWords: Array | undefined | null, checkOnly: false): Array | false | 'sensitiveMute';
+function checkMute(noteToCheck: Misskey.entities.Note, mutedWords: Array | undefined | null, checkOnly: false): string | string[] | false | 'sensitiveMute';
*/
-function checkMute(noteToCheck: Misskey.entities.Note, mutedWords: Array | undefined | null, checkOnly = false): Array | false | 'sensitiveMute' {
+function checkMute(noteToCheck: Misskey.entities.Note, mutedWords: Array | undefined | null, checkOnly = false): string | string[] | false | 'sensitiveMute' {
if (mutedWords == null) return false;
const result = checkWordMute(noteToCheck, $i, mutedWords);
- if (Array.isArray(result)) return result;
+ if (typeof result === 'string' || Array.isArray(result)) return result;
const replyResult = noteToCheck.reply && checkWordMute(noteToCheck.reply, $i, mutedWords);
- if (Array.isArray(replyResult)) return replyResult;
+ if (typeof replyResult === 'string' || Array.isArray(replyResult)) return replyResult;
const renoteResult = noteToCheck.renote && checkWordMute(noteToCheck.renote, $i, mutedWords);
- if (Array.isArray(renoteResult)) return renoteResult;
+ if (typeof renoteResult === 'string' || Array.isArray(renoteResult)) return renoteResult;
if (checkOnly) return false;
diff --git a/packages/frontend/src/scripts/check-word-mute.ts b/packages/frontend/src/scripts/check-word-mute.ts
index 98fea1bced..5f620ba6f1 100644
--- a/packages/frontend/src/scripts/check-word-mute.ts
+++ b/packages/frontend/src/scripts/check-word-mute.ts
@@ -4,7 +4,7 @@
*/
import * as Misskey from 'misskey-js';
-export function checkWordMute(note: Misskey.entities.Note, me: Misskey.entities.UserLite | null | undefined, mutedWords: Array): Array | false {
+export function checkWordMute(note: Misskey.entities.Note, me: Misskey.entities.UserLite | null | undefined, mutedWords: Array): string | string[] | false {
// 自分自身
if (me && (note.userId === me.id)) return false;
@@ -13,7 +13,7 @@ export function checkWordMute(note: Misskey.entities.Note, me: Misskey.entities.
if (text === '') return false;
- const matched = mutedWords.filter(filter => {
+ const matched = mutedWords.find((filter: string | string[]) => {
if (Array.isArray(filter)) {
// Clean up
const filteredFilter = filter.filter(keyword => keyword !== '');
@@ -36,7 +36,7 @@ export function checkWordMute(note: Misskey.entities.Note, me: Misskey.entities.
}
});
- if (matched.length > 0) return matched;
+ if (matched != null) return matched;
}
return false;