2023-07-26 22:31:52 -07:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-07-21 02:58:57 -07:00
|
|
|
import * as mfm from 'mfm-js';
|
2023-09-03 21:33:38 -07:00
|
|
|
import * as Misskey from 'misskey-js';
|
2023-09-19 00:37:43 -07:00
|
|
|
import { extractUrlFromMfm } from './extract-url-from-mfm.js';
|
2023-07-21 02:58:57 -07:00
|
|
|
|
2023-09-03 21:33:38 -07:00
|
|
|
export function shouldCollapsed(note: Misskey.entities.Note): boolean {
|
2023-07-21 02:58:57 -07:00
|
|
|
const urls = note.text ? extractUrlFromMfm(mfm.parse(note.text)) : null;
|
|
|
|
const collapsed = note.cw == null && note.text != null && (
|
|
|
|
(note.text.includes('$[x2')) ||
|
|
|
|
(note.text.includes('$[x3')) ||
|
|
|
|
(note.text.includes('$[x4')) ||
|
|
|
|
(note.text.includes('$[scale')) ||
|
|
|
|
(note.text.split('\n').length > 9) ||
|
|
|
|
(note.text.length > 500) ||
|
|
|
|
(note.files.length >= 5) ||
|
|
|
|
(!!urls && urls.length >= 4)
|
|
|
|
);
|
|
|
|
|
|
|
|
return collapsed;
|
|
|
|
}
|