summaryrefslogtreecommitdiff
path: root/src/api/endpoints/posts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-01-17 11:11:22 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-01-17 11:11:22 +0900
commit9f81288fccdbaf9184d49e61680747945b34f23d (patch)
treedce25db34136ffd9c05852ed4c2c493c23c96c07 /src/api/endpoints/posts
parentFix bug (diff)
downloadsharkey-9f81288fccdbaf9184d49e61680747945b34f23d.tar.gz
sharkey-9f81288fccdbaf9184d49e61680747945b34f23d.tar.bz2
sharkey-9f81288fccdbaf9184d49e61680747945b34f23d.zip
Fix bug
Diffstat (limited to 'src/api/endpoints/posts')
-rw-r--r--src/api/endpoints/posts/create.js18
-rw-r--r--src/api/endpoints/posts/likes.js5
-rw-r--r--src/api/endpoints/posts/likes/create.js6
-rw-r--r--src/api/endpoints/posts/likes/delete.js8
-rw-r--r--src/api/endpoints/posts/mentions.js5
-rw-r--r--src/api/endpoints/posts/replies.js5
-rw-r--r--src/api/endpoints/posts/reposts.js5
-rw-r--r--src/api/endpoints/posts/search.js8
-rw-r--r--src/api/endpoints/posts/timeline.js5
9 files changed, 28 insertions, 37 deletions
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
}
diff --git a/src/api/endpoints/posts/likes.js b/src/api/endpoints/posts/likes.js
index 4778189fc6..6d3ab866be 100644
--- a/src/api/endpoints/posts/likes.js
+++ b/src/api/endpoints/posts/likes.js
@@ -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 =>
diff --git a/src/api/endpoints/posts/likes/create.js b/src/api/endpoints/posts/likes/create.js
index eb35c1e4b0..73054be875 100644
--- a/src/api/endpoints/posts/likes/create.js
+++ b/src/api/endpoints/posts/likes/create.js
@@ -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
}
diff --git a/src/api/endpoints/posts/likes/delete.js b/src/api/endpoints/posts/likes/delete.js
index b60df63af5..b5b7e5177c 100644
--- a/src/api/endpoints/posts/likes/delete.js
+++ b/src/api/endpoints/posts/likes/delete.js
@@ -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
}
diff --git a/src/api/endpoints/posts/mentions.js b/src/api/endpoints/posts/mentions.js
index 6358e1f4a9..dbb69bd5ac 100644
--- a/src/api/endpoints/posts/mentions.js
+++ b/src/api/endpoints/posts/mentions.js
@@ -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 =>
diff --git a/src/api/endpoints/posts/replies.js b/src/api/endpoints/posts/replies.js
index 5eab6f896f..5ce1133e00 100644
--- a/src/api/endpoints/posts/replies.js
+++ b/src/api/endpoints/posts/replies.js
@@ -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 =>
diff --git a/src/api/endpoints/posts/reposts.js b/src/api/endpoints/posts/reposts.js
index 8b418a682f..a118ca6fba 100644
--- a/src/api/endpoints/posts/reposts.js
+++ b/src/api/endpoints/posts/reposts.js
@@ -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 =>
diff --git a/src/api/endpoints/posts/search.js b/src/api/endpoints/posts/search.js
index 0f214ef7ae..239517b993 100644
--- a/src/api/endpoints/posts/search.js
+++ b/src/api/endpoints/posts/search.js
@@ -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];
diff --git a/src/api/endpoints/posts/timeline.js b/src/api/endpoints/posts/timeline.js
index 489542da71..626f828ef8 100644
--- a/src/api/endpoints/posts/timeline.js
+++ b/src/api/endpoints/posts/timeline.js
@@ -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 =>