summaryrefslogtreecommitdiff
path: root/src/api/endpoints/posts
diff options
context:
space:
mode:
authorこぴなたみぽ <Syuilotan@yahoo.co.jp>2017-11-06 19:14:44 +0900
committerGitHub <noreply@github.com>2017-11-06 19:14:44 +0900
commit779011e5b3eb2601c5199b8733c0a07270026ad4 (patch)
tree258523215ed40a4b1ceb9f6e3c98d70ce6edbdb6 /src/api/endpoints/posts
parentfix(package): update cafy to version 3.1.1 (diff)
parentMerge pull request #876 from syuilo/greenkeeper/@types/body-parser-1.16.7 (diff)
downloadmisskey-779011e5b3eb2601c5199b8733c0a07270026ad4.tar.gz
misskey-779011e5b3eb2601c5199b8733c0a07270026ad4.tar.bz2
misskey-779011e5b3eb2601c5199b8733c0a07270026ad4.zip
Merge branch 'master' into greenkeeper/cafy-3.1.1
Diffstat (limited to 'src/api/endpoints/posts')
-rw-r--r--src/api/endpoints/posts/create.ts4
-rw-r--r--src/api/endpoints/posts/timeline.ts37
2 files changed, 20 insertions, 21 deletions
diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts
index f982b9ee93..4f4b7e2e83 100644
--- a/src/api/endpoints/posts/create.ts
+++ b/src/api/endpoints/posts/create.ts
@@ -44,9 +44,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
// SELECT _id
const entity = await DriveFile.findOne({
_id: mediaId,
- user_id: user._id
- }, {
- _id: true
+ 'metadata.user_id': user._id
});
if (entity === null) {
diff --git a/src/api/endpoints/posts/timeline.ts b/src/api/endpoints/posts/timeline.ts
index aa5aff5ba5..203413e23a 100644
--- a/src/api/endpoints/posts/timeline.ts
+++ b/src/api/endpoints/posts/timeline.ts
@@ -2,6 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
+import rap from '@prezzemolo/rap';
import Post from '../../models/post';
import ChannelWatching from '../../models/channel-watching';
import getFriends from '../../common/get-friends';
@@ -15,32 +16,33 @@ import serialize from '../../serializers/post';
* @param {any} app
* @return {Promise<any>}
*/
-module.exports = (params, user, app) => new Promise(async (res, rej) => {
+module.exports = async (params, user, app) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
- if (limitErr) return rej('invalid limit param');
+ if (limitErr) throw 'invalid limit param';
// Get 'since_id' parameter
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
- if (sinceIdErr) return rej('invalid since_id param');
+ if (sinceIdErr) throw 'invalid since_id param';
// Get 'max_id' parameter
const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
- if (maxIdErr) return rej('invalid max_id param');
+ if (maxIdErr) throw 'invalid max_id param';
// Check if both of since_id and max_id is specified
if (sinceId && maxId) {
- return rej('cannot set since_id and max_id');
+ throw 'cannot set since_id and max_id';
}
- // ID list of the user itself and other users who the user follows
- const followingIds = await getFriends(user._id);
-
- // Watchしているチャンネルを取得
- const watches = await ChannelWatching.find({
- user_id: user._id,
- // 削除されたドキュメントは除く
- deleted_at: { $exists: false }
+ const { followingIds, watchChannelIds } = await rap({
+ // ID list of the user itself and other users who the user follows
+ followingIds: getFriends(user._id),
+ // Watchしているチャンネルを取得
+ watchChannelIds: ChannelWatching.find({
+ user_id: user._id,
+ // 削除されたドキュメントは除く
+ deleted_at: { $exists: false }
+ }).then(watches => watches.map(w => w.channel_id))
});
//#region Construct query
@@ -65,7 +67,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
}, {
// Watchしているチャンネルへの投稿
channel_id: {
- $in: watches.map(w => w.channel_id)
+ $in: watchChannelIds
}
}]
} as any;
@@ -90,7 +92,6 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
});
// Serialize
- res(await Promise.all(timeline.map(async post =>
- await serialize(post, user)
- )));
-});
+ const _timeline = await Promise.all(timeline.map(post => serialize(post, user)));
+ return _timeline;
+};