jormungandr-bite/src/misc/get-note-summary.ts

55 lines
1.1 KiB
TypeScript
Raw Normal View History

2018-04-07 11:30:37 -06:00
/**
* 稿
* @param {*} note (packされた)稿
2018-04-07 11:30:37 -06:00
*/
const summarize = (note: any, locale: any): string => {
2018-05-27 23:39:46 -06:00
if (note.deletedAt) {
return `(${locale['deletedNote']})`;
2018-05-27 23:39:46 -06:00
}
2018-04-28 17:51:17 -06:00
if (note.isHidden) {
return `(${locale['invisibleNote']})`;
2018-04-28 17:51:17 -06:00
}
2018-04-07 11:30:37 -06:00
let summary = '';
// 本文
2018-12-19 11:22:27 -07:00
if (note.cw != null) {
2018-12-17 04:17:21 -07:00
summary += note.cw;
} else {
summary += note.text ? note.text : '';
}
2018-04-07 11:30:37 -06:00
2018-09-05 04:32:46 -06:00
// ファイルが添付されているとき
2018-10-08 14:31:26 -06:00
if ((note.files || []).length != 0) {
summary += ` (${locale['withNFiles'].replace('{n}', note.files.length)})`;
2018-04-07 11:30:37 -06:00
}
// 投票が添付されているとき
if (note.poll) {
summary += ` (${locale._cw?.poll || locale['_cw.poll']})`;
2018-04-07 11:30:37 -06:00
}
// 返信のとき
if (note.replyId) {
if (note.reply) {
summary += `\n\nRE: ${summarize(note.reply, locale)}`;
2018-04-07 11:30:37 -06:00
} else {
summary += '\n\nRE: ...';
2018-04-07 11:30:37 -06:00
}
}
// Renoteのとき
if (note.renoteId) {
if (note.renote) {
summary += `\n\nRN: ${summarize(note.renote, locale)}`;
2018-04-07 11:30:37 -06:00
} else {
summary += '\n\nRN: ...';
2018-04-07 11:30:37 -06:00
}
}
return summary.trim();
};
export default summarize;