From 9f81288fccdbaf9184d49e61680747945b34f23d Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 17 Jan 2017 11:11:22 +0900 Subject: Fix bug --- src/api/endpoints/posts/create.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/api/endpoints/posts/create.js') diff --git a/src/api/endpoints/posts/create.js b/src/api/endpoints/posts/create.js index 694e6fc824..c3291bc725 100644 --- a/src/api/endpoints/posts/create.js +++ b/src/api/endpoints/posts/create.js @@ -13,6 +13,7 @@ import serialize from '../../serializers/post'; import createFile from '../../common/add-file-to-drive'; import notify from '../../common/notify'; import event from '../../event'; +import config from '../../../conf'; /** * 最大文字数 @@ -103,7 +104,7 @@ module.exports = (params, user, app) => // Fetch recently post const latestPost = await Post.findOne({ user_id: user._id - }, {}, { + }, { sort: { _id: -1 } @@ -152,7 +153,7 @@ module.exports = (params, user, app) => } // 投稿を作成 - const inserted = await Post.insert({ + const post = await Post.insert({ created_at: new Date(), media_ids: media ? files.map(file => file._id) : undefined, reply_to_id: replyTo ? replyTo._id : undefined, @@ -162,8 +163,6 @@ module.exports = (params, user, app) => app_id: app ? app._id : null }); - const post = inserted.ops[0]; - // Serialize const postObj = await serialize(post); @@ -200,15 +199,14 @@ module.exports = (params, user, app) => }, { follower_id: true, _id: false - }) - .toArray(); + }); // Publish event to followers stream followers.forEach(following => event(following.follower_id, 'post', postObj)); // Increment my posts count - User.updateOne({ _id: user._id }, { + User.update({ _id: user._id }, { $inc: { posts_count: 1 } @@ -217,7 +215,7 @@ module.exports = (params, user, app) => // If has in reply to post if (replyTo) { // Increment replies count - Post.updateOne({ _id: replyTo._id }, { + Post.update({ _id: replyTo._id }, { $inc: { replies_count: 1 } @@ -262,7 +260,7 @@ module.exports = (params, user, app) => if (!existRepost) { // Update repostee status - Post.updateOne({ _id: repost._id }, { + Post.update({ _id: repost._id }, { $inc: { repost_count: 1 } @@ -336,7 +334,7 @@ module.exports = (params, user, app) => // Append mentions data if (mentions.length > 0) { - Post.updateOne({ _id: post._id }, { + Post.update({ _id: post._id }, { $set: { mentions: mentions } -- cgit v1.3.1-freya