Sharkey/src/misc/get-note-summary.ts

55 lines
1,016 B
TypeScript
Raw Normal View History

2018-04-07 20:30:37 +03:00
/**
* 稿
* @param {*} note (packされた)稿
2018-04-07 20:30:37 +03:00
*/
const summarize = (note: any): string => {
2018-05-28 08:39:46 +03:00
if (note.deletedAt) {
return '(削除された投稿)';
}
2018-04-29 02:51:17 +03:00
if (note.isHidden) {
return '(非公開の投稿)';
}
2018-04-07 20:30:37 +03:00
let summary = '';
// 本文
2018-12-17 13:17:21 +02:00
if (note.cw && note.cw != '') {
summary += note.cw;
} else {
summary += note.text ? note.text : '';
}
2018-04-07 20:30:37 +03:00
2018-09-05 13:32:46 +03:00
// ファイルが添付されているとき
2018-10-08 23:31:26 +03:00
if ((note.files || []).length != 0) {
2018-09-05 13:32:46 +03:00
summary += ` (${note.files.length}つのファイル)`;
2018-04-07 20:30:37 +03:00
}
// 投票が添付されているとき
if (note.poll) {
summary += ' (投票)';
}
// 返信のとき
if (note.replyId) {
if (note.reply) {
summary += `\n\nRE: ${summarize(note.reply)}`;
2018-04-07 20:30:37 +03:00
} else {
summary += '\n\nRE: ...';
2018-04-07 20:30:37 +03:00
}
}
// Renoteのとき
if (note.renoteId) {
if (note.renote) {
summary += `\n\nRN: ${summarize(note.renote)}`;
2018-04-07 20:30:37 +03:00
} else {
summary += '\n\nRN: ...';
2018-04-07 20:30:37 +03:00
}
}
return summary.trim();
};
export default summarize;