2023-07-27 14:31:52 +09:00
|
|
|
/*
|
2024-02-14 00:59:27 +09:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 14:31:52 +09:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-03-10 14:22:37 +09:00
|
|
|
import type { Packed } from './json-schema.js';
|
2021-11-12 02:02:25 +09:00
|
|
|
|
2018-04-08 02:30:37 +09:00
|
|
|
/**
|
|
|
|
* 投稿を表す文字列を取得します。
|
2018-05-06 01:34:48 +09:00
|
|
|
* @param {*} note (packされた)投稿
|
2018-04-08 02:30:37 +09:00
|
|
|
*/
|
2021-11-12 02:02:25 +09:00
|
|
|
export const getNoteSummary = (note: Packed<'Note'>): string => {
|
2018-05-28 14:39:46 +09:00
|
|
|
if (note.deletedAt) {
|
2022-09-18 03:27:08 +09:00
|
|
|
return '(❌⛔)';
|
2018-05-28 14:39:46 +09:00
|
|
|
}
|
|
|
|
|
2018-04-29 08:51:17 +09:00
|
|
|
if (note.isHidden) {
|
2022-09-18 03:27:08 +09:00
|
|
|
return '(⛔)';
|
2018-04-29 08:51:17 +09:00
|
|
|
}
|
|
|
|
|
2018-04-08 02:30:37 +09:00
|
|
|
let summary = '';
|
|
|
|
|
|
|
|
// 本文
|
2018-12-20 03:22:27 +09:00
|
|
|
if (note.cw != null) {
|
2018-12-17 20:17:21 +09:00
|
|
|
summary += note.cw;
|
|
|
|
} else {
|
|
|
|
summary += note.text ? note.text : '';
|
|
|
|
}
|
2018-04-08 02:30:37 +09:00
|
|
|
|
2018-09-05 19:32:46 +09:00
|
|
|
// ファイルが添付されているとき
|
2022-09-18 03:27:08 +09:00
|
|
|
if ((note.files ?? []).length !== 0) {
|
2021-11-12 02:02:25 +09:00
|
|
|
summary += ` (📎${note.files!.length})`;
|
2018-04-08 02:30:37 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// 投票が添付されているとき
|
|
|
|
if (note.poll) {
|
2022-09-18 03:27:08 +09:00
|
|
|
summary += ' (📊)';
|
2018-04-08 02:30:37 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// 返信のとき
|
|
|
|
if (note.replyId) {
|
|
|
|
if (note.reply) {
|
2021-11-12 02:02:25 +09:00
|
|
|
summary += `\n\nRE: ${getNoteSummary(note.reply)}`;
|
2018-04-08 02:30:37 +09:00
|
|
|
} else {
|
2018-11-30 09:34:37 +09:00
|
|
|
summary += '\n\nRE: ...';
|
2018-04-08 02:30:37 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Renoteのとき
|
|
|
|
if (note.renoteId) {
|
|
|
|
if (note.renote) {
|
2021-11-12 02:02:25 +09:00
|
|
|
summary += `\n\nRN: ${getNoteSummary(note.renote)}`;
|
2018-04-08 02:30:37 +09:00
|
|
|
} else {
|
2018-11-30 09:34:37 +09:00
|
|
|
summary += '\n\nRN: ...';
|
2018-04-08 02:30:37 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return summary.trim();
|
|
|
|
};
|