1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-12-02 16:58:49 +09:00
This commit is contained in:
syuilo 2017-03-03 06:37:09 +09:00
parent 9d3dff8805
commit d3c4cd1c43

View File

@ -3,7 +3,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import * as mongo from 'mongodb'; import it from '../../it';
import Post from '../../models/post'; import Post from '../../models/post';
import getFriends from '../../common/get-friends'; import getFriends from '../../common/get-friends';
import serialize from '../../serializers/post'; import serialize from '../../serializers/post';
@ -19,33 +19,31 @@ module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>
{ {
// Get 'following' parameter // Get 'following' parameter
const following = params.following; const [following, followingError] =
it(params.following).expect.boolean().default(false).qed();
if (followingError) return rej('invalid following param');
// Get 'limit' parameter // Get 'limit' parameter
let limit = params.limit; const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
if (limit !== undefined && limit !== null) { if (limitErr) return rej('invalid limit param');
limit = parseInt(limit, 10);
// From 1 to 100 // Get 'since_id' parameter
if (!(1 <= limit && limit <= 100)) { const [sinceId, sinceIdErr] = it(params.since_id).expect.id().qed();
return rej('invalid limit range'); if (sinceIdErr) return rej('invalid since_id param');
}
} else {
limit = 10;
}
const since = params.since_id || null; // Get 'max_id' parameter
const max = params.max_id || null; const [maxId, maxIdErr] = it(params.max_id).expect.id().qed();
if (maxIdErr) return rej('invalid max_id param');
// Check if both of since_id and max_id is specified // Check if both of since_id and max_id is specified
if (since !== null && max !== null) { if (sinceId !== null && maxId !== null) {
return rej('cannot set since_id and max_id'); return rej('cannot set since_id and max_id');
} }
// Construct query // Construct query
const query = { const query = {
mentions: user._id mentions: user._id
}; } as any;
const sort = { const sort = {
_id: -1 _id: -1
@ -59,14 +57,14 @@ module.exports = (params, user) =>
}; };
} }
if (since) { if (sinceId) {
sort._id = 1; sort._id = 1;
query._id = { query._id = {
$gt: new mongo.ObjectID(since) $gt: sinceId
}; };
} else if (max) { } else if (maxId) {
query._id = { query._id = {
$lt: new mongo.ObjectID(max) $lt: maxId
}; };
} }