From ab8eefda25870a0495f4ba71f34ca4dae696d645 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 17 Mar 2018 23:01:17 +0900 Subject: [PATCH] :v: --- src/api/endpoints/users.ts | 48 +++++++++---------- .../views/components/welcome-timeline.vue | 5 +- src/web/app/desktop/views/pages/welcome.vue | 41 ++++++++++++---- src/web/app/mobile/views/pages/welcome.vue | 44 ++++++++++++++--- 4 files changed, 96 insertions(+), 42 deletions(-) diff --git a/src/api/endpoints/users.ts b/src/api/endpoints/users.ts index 095b9fe40d..249faed368 100644 --- a/src/api/endpoints/users.ts +++ b/src/api/endpoints/users.ts @@ -16,40 +16,38 @@ module.exports = (params, me) => new Promise(async (res, rej) => { const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$; if (limitErr) return rej('invalid limit param'); - // Get 'since_id' parameter - const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$; - if (sinceIdErr) return rej('invalid since_id param'); + // Get 'offset' parameter + const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).$; + if (offsetErr) return rej('invalid offset param'); - // Get 'until_id' parameter - const [untilId, untilIdErr] = $(params.until_id).optional.id().$; - if (untilIdErr) return rej('invalid until_id param'); - - // Check if both of since_id and until_id is specified - if (sinceId && untilId) { - return rej('cannot set since_id and until_id'); - } + // Get 'sort' parameter + const [sort, sortError] = $(params.sort).optional.string().or('+follower|-follower').$; + if (sortError) return rej('invalid sort param'); // Construct query - const sort = { - _id: -1 - }; - const query = {} as any; - if (sinceId) { - sort._id = 1; - query._id = { - $gt: sinceId - }; - } else if (untilId) { - query._id = { - $lt: untilId + let _sort; + if (sort) { + if (sort == '+follower') { + _sort = { + followers_count: 1 + }; + } else if (sort == '-follower') { + _sort = { + followers_count: -1 + }; + } + } else { + _sort = { + _id: -1 }; } // Issue query const users = await User - .find(query, { + .find({}, { limit: limit, - sort: sort + sort: _sort, + skip: offset }); // Serialize diff --git a/src/web/app/common/views/components/welcome-timeline.vue b/src/web/app/common/views/components/welcome-timeline.vue index 2ff06e2cc0..7e35e1f71b 100644 --- a/src/web/app/common/views/components/welcome-timeline.vue +++ b/src/web/app/common/views/components/welcome-timeline.vue @@ -1,12 +1,12 @@