This commit is contained in:
syuilo
2017-10-07 06:58:50 +09:00
parent 1d4f9378ca
commit fe98dd927d
15 changed files with 28 additions and 15 deletions

View File

@@ -0,0 +1,39 @@
/**
* 投稿を表す文字列を取得します。
* @param {*} post 投稿
*/
const summarize = (post: any): string => {
let summary = post.text ? post.text : '';
// メディアが添付されているとき
if (post.media) {
summary += ` (${post.media.length}つのメディア)`;
}
// 投票が添付されているとき
if (post.poll) {
summary += ' (投票)';
}
// 返信のとき
if (post.reply_to_id) {
if (post.reply_to) {
summary += ` RE: ${summarize(post.reply_to)}`;
} else {
summary += ' RE: ...';
}
}
// Repostのとき
if (post.repost_id) {
if (post.repost) {
summary += ` RP: ${summarize(post.repost)}`;
} else {
summary += ' RP: ...';
}
}
return summary.trim();
};
export default summarize;