From 3b77bc8299eee89a7945438863953a5cdd08e934 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 28 Aug 2017 00:03:57 +0900 Subject: [PATCH] Implement #734 --- CHANGELOG.md | 4 + locales/en.yml | 4 + locales/ja.yml | 4 + src/api/serializers/post.ts | 93 ++++++++++++++++-------- src/web/app/desktop/tags/pages/post.tag | 34 +++++++-- src/web/app/desktop/tags/post-detail.tag | 76 +++++++------------ 6 files changed, 132 insertions(+), 83 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72a584ddb0..95d21ac05f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ChangeLog ========= 主に notable な changes を書いていきます +unreleased +---------- +* 投稿ページに次の投稿/前の投稿リンクを作成 (#734) + 2380 ---- アプリケーションが作れない問題を修正 diff --git a/locales/en.yml b/locales/en.yml index 55a588f99f..9bf6446641 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -231,6 +231,10 @@ desktop: attaches: "{} media attached" uploading-media: "Uploading {} media" + mk-post-page: + prev: "Previous post" + next: "Next post" + mk-timeline-post: reposted-by: "Reposted by {}" reply: "Reply" diff --git a/locales/ja.yml b/locales/ja.yml index e5b2beaed1..d2b282bff6 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -231,6 +231,10 @@ desktop: attaches: "添付: {}メディア" uploading-media: "{}個のメディアをアップロード中" + mk-post-page: + prev: "前の投稿" + next: "次の投稿" + mk-timeline-post: reposted-by: "{}がRepost" reply: "返信" 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 }); + } - if (reaction) { - _post.my_reaction = reaction.reaction; + // 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; + } } } diff --git a/src/web/app/desktop/tags/pages/post.tag b/src/web/app/desktop/tags/pages/post.tag index c91e98bbd4..f270b43ac2 100644 --- a/src/web/app/desktop/tags/pages/post.tag +++ b/src/web/app/desktop/tags/pages/post.tag @@ -1,7 +1,9 @@ -
+
+ %i18n:desktop.tags.mk-post-page.next% + %i18n:desktop.tags.mk-post-page.prev%