rudeshark.net/src/common/get-post-summary.ts

46 lines
859 B
TypeScript
Raw Normal View History

2017-10-06 20:36:46 +02:00
/**
* 稿
* @param {*} post 稿
*/
2017-10-06 23:58:50 +02:00
const summarize = (post: any): string => {
2017-10-31 20:16:16 +01:00
let summary = '';
// チャンネル
summary += post.channel ? `${post.channel.title}:` : '';
// 本文
summary += post.text ? post.text : '';
2017-02-18 05:07:34 +01:00
// メディアが添付されているとき
if (post.media) {
summary += ` (${post.media.length}つのメディア)`;
}
// 投票が添付されているとき
if (post.poll) {
summary += ' (投票)';
}
// 返信のとき
2017-11-01 02:22:40 +01:00
if (post.reply_id) {
if (post.reply) {
summary += ` RE: ${summarize(post.reply)}`;
2017-02-18 05:07:34 +01:00
} else {
summary += ' RE: ...';
}
}
// Repostのとき
if (post.repost_id) {
if (post.repost) {
2017-02-19 04:27:43 +01:00
summary += ` RP: ${summarize(post.repost)}`;
2017-02-18 05:07:34 +01:00
} else {
summary += ' RP: ...';
}
}
return summary.trim();
};
2017-03-18 12:05:11 +01:00
export default summarize;