diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-08-28 00:03:57 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-08-28 00:03:57 +0900 |
| commit | 3b77bc8299eee89a7945438863953a5cdd08e934 (patch) | |
| tree | 37750370f12cc74c6512bf3cce08d3839c601774 /src/api | |
| parent | Merge pull request #715 from syuilo/greenkeeper/@types/event-stream-3.3.32 (diff) | |
| download | sharkey-3b77bc8299eee89a7945438863953a5cdd08e934.tar.gz sharkey-3b77bc8299eee89a7945438863953a5cdd08e934.tar.bz2 sharkey-3b77bc8299eee89a7945438863953a5cdd08e934.zip | |
Implement #734
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/serializers/post.ts | 93 |
1 files changed, 64 insertions, 29 deletions
diff --git a/src/api/serializers/post.ts b/src/api/serializers/post.ts index 3c96884dd1..13773bda9e 100644 --- a/src/api/serializers/post.ts +++ b/src/api/serializers/post.ts @@ -73,44 +73,79 @@ const self = ( )); } - if (_post.reply_to_id && opts.detail) { - // Populate reply to post - _post.reply_to = await self(_post.reply_to_id, me, { - detail: false + // When requested a detailed post data + if (opts.detail) { + // Get previous post info + const prev = await Post.findOne({ + user_id: _post.user_id, + _id: { + $lt: id + } + }, { + fields: { + _id: true + }, + sort: { + _id: -1 + } }); - } + _post.prev = prev ? prev._id : null; - if (_post.repost_id && opts.detail) { - // Populate repost - _post.repost = await self(_post.repost_id, me, { - detail: _post.text == null + // Get next post info + const next = await Post.findOne({ + user_id: _post.user_id, + _id: { + $gt: id + } + }, { + fields: { + _id: true + }, + sort: { + _id: 1 + } }); - } + _post.next = next ? next._id : null; - // Poll - if (me && _post.poll && opts.detail) { - const vote = await Vote - .findOne({ - user_id: me._id, - post_id: id + if (_post.reply_to_id) { + // Populate reply to post + _post.reply_to = await self(_post.reply_to_id, me, { + detail: false }); - - if (vote != null) { - _post.poll.choices.filter(c => c.id == vote.choice)[0].is_voted = true; } - } - // Fetch my reaction - if (me && opts.detail) { - const reaction = await Reaction - .findOne({ - user_id: me._id, - post_id: id, - deleted_at: { $exists: false } + if (_post.repost_id) { + // Populate repost + _post.repost = await self(_post.repost_id, me, { + detail: _post.text == null }); + } + + // Poll + if (me && _post.poll) { + const vote = await Vote + .findOne({ + user_id: me._id, + post_id: id + }); + + if (vote != null) { + _post.poll.choices.filter(c => c.id == vote.choice)[0].is_voted = true; + } + } + + // Fetch my reaction + if (me) { + const reaction = await Reaction + .findOne({ + user_id: me._id, + post_id: id, + deleted_at: { $exists: false } + }); - if (reaction) { - _post.my_reaction = reaction.reaction; + if (reaction) { + _post.my_reaction = reaction.reaction; + } } } |