From 6271c70d3cdbc5c55a158dcfe7d78ec3824af495 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 19 Mar 2017 15:23:30 +0900 Subject: [PATCH] [API] Better public timeline api (BREAKING) --- src/api/endpoints/posts.ts | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/api/endpoints/posts.ts b/src/api/endpoints/posts.ts index 999d63a86..23b9bd0b6 100644 --- a/src/api/endpoints/posts.ts +++ b/src/api/endpoints/posts.ts @@ -12,13 +12,21 @@ import serialize from '../serializers/post'; * @return {Promise} */ 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