diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-10-07 03:36:46 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-10-07 03:36:46 +0900 |
| commit | 6a5c6280ffd3ffe820beb23294f1c2c1f5deb9cf (patch) | |
| tree | eb9006394a36bfa80bd255e9d86a524060c37828 /src/common | |
| parent | Merge pull request #817 from syuilo/greenkeeper/@types/mongodb-2.2.13 (diff) | |
| download | sharkey-6a5c6280ffd3ffe820beb23294f1c2c1f5deb9cf.tar.gz sharkey-6a5c6280ffd3ffe820beb23294f1c2c1f5deb9cf.tar.bz2 sharkey-6a5c6280ffd3ffe820beb23294f1c2c1f5deb9cf.zip | |
:v:
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/get-post-summary.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/common/get-post-summary.js b/src/common/get-post-summary.js new file mode 100644 index 0000000000..f7a481a164 --- /dev/null +++ b/src/common/get-post-summary.js @@ -0,0 +1,39 @@ +/** + * 投稿を表す文字列を取得します。 + * @param {*} post 投稿 + */ +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; |