perf: filter -> findに変更して最初の一個のみを表示するように変更

This commit is contained in:
taichan 2025-01-14 13:07:38 +00:00
parent 98984e4af5
commit 72ef92f0d6
2 changed files with 9 additions and 9 deletions

View File

@ -164,7 +164,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</MkA> </MkA>
</template> </template>
<template #word> <template #word>
{{ Array.isArray(muted) ? muted.map(words => Array.isArray(words) ? words.join() : words).slice(0, 3).join(' ') : muted }} {{ Array.isArray(muted) ? muted.join(' ') : muted }}
</template> </template>
</I18n> </I18n>
</div> </div>
@ -301,19 +301,19 @@ const pleaseLoginContext = computed<OpenOnRemoteOptions>(() => ({
/* Overload FunctionLint /* Overload FunctionLint
function checkMute(noteToCheck: Misskey.entities.Note, mutedWords: Array<string | string[]> | undefined | null, checkOnly: true): boolean; function checkMute(noteToCheck: Misskey.entities.Note, mutedWords: Array<string | string[]> | undefined | null, checkOnly: true): boolean;
function checkMute(noteToCheck: Misskey.entities.Note, mutedWords: Array<string | string[]> | undefined | null, checkOnly: false): Array<string | string[]> | false | 'sensitiveMute'; function checkMute(noteToCheck: Misskey.entities.Note, mutedWords: Array<string | string[]> | undefined | null, checkOnly: false): string | string[] | false | 'sensitiveMute';
*/ */
function checkMute(noteToCheck: Misskey.entities.Note, mutedWords: Array<string | string[]> | undefined | null, checkOnly = false): Array<string | string[]> | false | 'sensitiveMute' { function checkMute(noteToCheck: Misskey.entities.Note, mutedWords: Array<string | string[]> | undefined | null, checkOnly = false): string | string[] | false | 'sensitiveMute' {
if (mutedWords == null) return false; if (mutedWords == null) return false;
const result = checkWordMute(noteToCheck, $i, mutedWords); 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); 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); 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; if (checkOnly) return false;

View File

@ -4,7 +4,7 @@
*/ */
import * as Misskey from 'misskey-js'; import * as Misskey from 'misskey-js';
export function checkWordMute(note: Misskey.entities.Note, me: Misskey.entities.UserLite | null | undefined, mutedWords: Array<string | string[]>): Array<string | string[]> | false { export function checkWordMute(note: Misskey.entities.Note, me: Misskey.entities.UserLite | null | undefined, mutedWords: Array<string | string[]>): string | string[] | false {
// 自分自身 // 自分自身
if (me && (note.userId === me.id)) return 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; if (text === '') return false;
const matched = mutedWords.filter(filter => { const matched = mutedWords.find((filter: string | string[]) => {
if (Array.isArray(filter)) { if (Array.isArray(filter)) {
// Clean up // Clean up
const filteredFilter = filter.filter(keyword => keyword !== ''); 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; return false;