[API] Better public timeline api (BREAKING)

This commit is contained in:
syuilo 2017-03-19 15:23:30 +09:00
parent 898daf24d1
commit 6271c70d3c

View file

@ -12,13 +12,21 @@ import serialize from '../serializers/post';
* @return {Promise<any>}
*/
module.exports = (params) => new Promise(async (res, rej) => {
// Get 'include_replies' parameter
const [includeReplies = true, includeRepliesErr] = $(params.include_replies).optional.boolean().$;
if (includeRepliesErr) return rej('invalid include_replies param');
// Get 'reply' parameter
const [reply, replyErr] = $(params.reply).optional.boolean().$;
if (replyErr) return rej('invalid reply param');
// Get 'include_reposts' parameter
const [includeReposts = true, includeRepostsErr] = $(params.include_reposts).optional.boolean().$;
if (includeRepostsErr) return rej('invalid include_reposts param');
// Get 'repost' parameter
const [repost, repostErr] = $(params.repost).optional.boolean().$;
if (repostErr) return rej('invalid repost param');
// Get 'media' parameter
const [media, mediaErr] = $(params.media).optional.boolean().$;
if (mediaErr) return rej('invalid media param');
// Get 'poll' parameter
const [poll, pollErr] = $(params.poll).optional.boolean().$;
if (pollErr) return rej('invalid poll param');
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
@ -53,12 +61,20 @@ module.exports = (params) => new Promise(async (res, rej) => {
};
}
if (!includeReplies) {
query.reply_to_id = null;
if (reply != undefined) {
query.reply_to_id = reply ? { $exists: true, $ne: null } : null;
}
if (!includeReposts) {
query.repost_id = null;
if (repost != undefined) {
query.repost_id = repost ? { $exists: true, $ne: null } : null;
}
if (media != undefined) {
query.media_ids = media ? { $exists: true, $ne: null } : null;
}
if (poll != undefined) {
query.poll = poll ? { $exists: true, $ne: null } : null;
}
// Issue query