1
0
forked from mirror/misskey
misskey/src/misc/get-note-summary.ts

53 lines
1.0 KiB
TypeScript
Raw Normal View History

2018-04-08 02:30:37 +09:00
/**
* 稿
* @param {*} note (packされた)稿
2018-04-08 02:30:37 +09:00
*/
2020-12-28 23:05:30 +09:00
export const getNoteSummary = (note: any, locale: any): string => {
2018-05-28 14:39:46 +09:00
if (note.deletedAt) {
return `(${locale['deletedNote']})`;
2018-05-28 14:39:46 +09:00
}
2018-04-29 08:51:17 +09:00
if (note.isHidden) {
return `(${locale['invisibleNote']})`;
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
// ファイルが添付されているとき
2018-10-09 05:31:26 +09:00
if ((note.files || []).length != 0) {
summary += ` (${locale['withNFiles'].replace('{n}', note.files.length)})`;
2018-04-08 02:30:37 +09:00
}
// 投票が添付されているとき
if (note.poll) {
summary += ` (${locale['poll']})`;
2018-04-08 02:30:37 +09:00
}
// 返信のとき
if (note.replyId) {
if (note.reply) {
2020-12-28 23:41:09 +09:00
summary += `\n\nRE: ${getNoteSummary(note.reply, locale)}`;
2018-04-08 02:30:37 +09:00
} else {
summary += '\n\nRE: ...';
2018-04-08 02:30:37 +09:00
}
}
// Renoteのとき
if (note.renoteId) {
if (note.renote) {
2020-12-28 23:41:09 +09:00
summary += `\n\nRN: ${getNoteSummary(note.renote, locale)}`;
2018-04-08 02:30:37 +09:00
} else {
summary += '\n\nRN: ...';
2018-04-08 02:30:37 +09:00
}
}
return summary.trim();
};