Sharkey/src/web/app/common/scripts/get-post-summary.js
syuilo 45e8331e26 🍣
Closes #12, #227 and #58
2017-03-18 20:05:11 +09:00

36 lines
663 B
JavaScript

const summarize = post => {
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;