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