astが提供されていない場合はパースするように

This commit is contained in:
kakkokari-gtyih 2024-04-28 21:05:16 +09:00
parent cf48dbf6c8
commit b0fe6ea048
1 changed files with 4 additions and 2 deletions

View File

@ -10,10 +10,12 @@ import { safeParseFloat } from './safe-parse.js';
export function shouldCollapsed(note: Misskey.entities.Note, ast?: mfm.MfmNode[] | null, urls?: string[]): boolean { export function shouldCollapsed(note: Misskey.entities.Note, ast?: mfm.MfmNode[] | null, urls?: string[]): boolean {
if (note.cw != null) return false; if (note.cw != null) return false;
if (note.text == null) return false; if (note.text == null) return false;
if (ast == null) return false;
if (note.files && note.files.length >= 5) return true; if (note.files && note.files.length >= 5) return true;
if (urls && urls.length >= 4) return true; if (urls && urls.length >= 4) return true;
// ASTが提供されていない場合はパースしちゃう
const _ast = ast ?? mfm.parse(note.text);
// しきい値X方向の文字数は半角換算 // しきい値X方向の文字数は半角換算
const limitX = 55; const limitX = 55;
const limitY = 13.5; const limitY = 13.5;
@ -197,7 +199,7 @@ export function shouldCollapsed(note: Misskey.entities.Note, ast?: mfm.MfmNode[]
return vHeight; return vHeight;
} }
const virtualHeight = getHeight(ast); const virtualHeight = getHeight(_ast);
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
return forceCollapsed || virtualHeight > limitY; return forceCollapsed || virtualHeight > limitY;