Fix bug
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
@@ -62,14 +62,13 @@ module.exports = (params, user) =>
|
||||
.find({
|
||||
post_id: post._id,
|
||||
deleted_at: { $exists: false }
|
||||
}, {}, {
|
||||
}, {
|
||||
limit: limit,
|
||||
skip: offset,
|
||||
sort: {
|
||||
_id: sort == 'asc' ? 1 : -1
|
||||
}
|
||||
})
|
||||
.toArray();
|
||||
});
|
||||
|
||||
// Serialize
|
||||
res(await Promise.all(likes.map(async like =>
|
||||
|
@@ -66,21 +66,21 @@ module.exports = (params, user) =>
|
||||
res();
|
||||
|
||||
// Increment likes count
|
||||
Post.updateOne({ _id: post._id }, {
|
||||
Post.update({ _id: post._id }, {
|
||||
$inc: {
|
||||
likes_count: 1
|
||||
}
|
||||
});
|
||||
|
||||
// Increment user likes count
|
||||
User.updateOne({ _id: user._id }, {
|
||||
User.update({ _id: user._id }, {
|
||||
$inc: {
|
||||
likes_count: 1
|
||||
}
|
||||
});
|
||||
|
||||
// Increment user liked count
|
||||
User.updateOne({ _id: post.user_id }, {
|
||||
User.update({ _id: post.user_id }, {
|
||||
$inc: {
|
||||
liked_count: 1
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ module.exports = (params, user) =>
|
||||
}
|
||||
|
||||
// Delete like
|
||||
await Like.updateOne({
|
||||
await Like.update({
|
||||
_id: exist._id
|
||||
}, {
|
||||
$set: {
|
||||
@@ -58,21 +58,21 @@ module.exports = (params, user) =>
|
||||
res();
|
||||
|
||||
// Decrement likes count
|
||||
Post.updateOne({ _id: post._id }, {
|
||||
Post.update({ _id: post._id }, {
|
||||
$inc: {
|
||||
likes_count: -1
|
||||
}
|
||||
});
|
||||
|
||||
// Decrement user likes count
|
||||
User.updateOne({ _id: user._id }, {
|
||||
User.update({ _id: user._id }, {
|
||||
$inc: {
|
||||
likes_count: -1
|
||||
}
|
||||
});
|
||||
|
||||
// Decrement user liked count
|
||||
User.updateOne({ _id: post.user_id }, {
|
||||
User.update({ _id: post.user_id }, {
|
||||
$inc: {
|
||||
liked_count: -1
|
||||
}
|
||||
|
@@ -72,11 +72,10 @@ module.exports = (params, user) =>
|
||||
|
||||
// Issue query
|
||||
const mentions = await Post
|
||||
.find(query, {}, {
|
||||
.find(query, {
|
||||
limit: limit,
|
||||
sort: sort
|
||||
})
|
||||
.toArray();
|
||||
});
|
||||
|
||||
// Serialize
|
||||
res(await Promise.all(mentions.map(async mention =>
|
||||
|
@@ -58,14 +58,13 @@ module.exports = (params, user) =>
|
||||
|
||||
// Issue query
|
||||
const replies = await Post
|
||||
.find({ reply_to_id: post._id }, {}, {
|
||||
.find({ reply_to_id: post._id }, {
|
||||
limit: limit,
|
||||
skip: offset,
|
||||
sort: {
|
||||
_id: sort == 'asc' ? 1 : -1
|
||||
}
|
||||
})
|
||||
.toArray();
|
||||
});
|
||||
|
||||
// Serialize
|
||||
res(await Promise.all(replies.map(async post =>
|
||||
|
@@ -73,11 +73,10 @@ module.exports = (params, user) =>
|
||||
|
||||
// Issue query
|
||||
const reposts = await Post
|
||||
.find(query, {}, {
|
||||
.find(query, {
|
||||
limit: limit,
|
||||
sort: sort
|
||||
})
|
||||
.toArray();
|
||||
});
|
||||
|
||||
// Serialize
|
||||
res(await Promise.all(reposts.map(async post =>
|
||||
|
@@ -65,8 +65,7 @@ async function byNative(res, rej, me, query, offset, max) {
|
||||
},
|
||||
limit: max,
|
||||
skip: offset
|
||||
})
|
||||
.toArray();
|
||||
});
|
||||
|
||||
// Serialize
|
||||
res(await Promise.all(posts.map(async post =>
|
||||
@@ -120,12 +119,11 @@ async function byElasticsearch(res, rej, me, query, offset, max) {
|
||||
_id: {
|
||||
$in: hits
|
||||
}
|
||||
}, {}, {
|
||||
}, {
|
||||
sort: {
|
||||
_id: -1
|
||||
}
|
||||
})
|
||||
.toArray();
|
||||
});
|
||||
|
||||
posts.map(post => {
|
||||
post._highlight = response.hits.hits.filter(hit => post._id.equals(hit._id))[0].highlight.text[0];
|
||||
|
@@ -65,11 +65,10 @@ module.exports = (params, user, app) =>
|
||||
|
||||
// Issue query
|
||||
const timeline = await Post
|
||||
.find(query, {}, {
|
||||
.find(query, {
|
||||
limit: limit,
|
||||
sort: sort
|
||||
})
|
||||
.toArray();
|
||||
});
|
||||
|
||||
// Serialize
|
||||
res(await Promise.all(timeline.map(async post =>
|
||||
|
Reference in New Issue
Block a user