From db5bdcd85516484617f7d4eee53fdcb586abd897 Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Thu, 4 Jan 2018 01:07:14 +0100 Subject: [PATCH] feat: backport after and before parameter when fetching a reaction's users (#2218) Commits: - https://github.com/hydrabolt/discord.js/commit/f40a5e9f8875299aa6ec25a0491e4dc92868f54d - https://github.com/hydrabolt/discord.js/commit/5cd42695aeb974e998d4b220cba1c27b30a55628 --- src/client/rest/RESTMethods.js | 6 ++++-- src/structures/MessageReaction.js | 9 +++++---- src/util/Constants.js | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/client/rest/RESTMethods.js b/src/client/rest/RESTMethods.js index d3b54d91f..e0ff6bec0 100644 --- a/src/client/rest/RESTMethods.js +++ b/src/client/rest/RESTMethods.js @@ -914,8 +914,10 @@ class RESTMethods { .then(() => message); } - getMessageReactionUsers(message, emoji, limit = 100) { - return this.rest.makeRequest('get', Endpoints.Message(message).Reaction(emoji, limit), true); + getMessageReactionUsers(message, emoji, options) { + const queryString = (querystring.stringify(options).match(/[^=&?]+=[^=&?]+/g) || []).join('&'); + + return this.rest.makeRequest('get', `${Endpoints.Message(message).Reaction(emoji)}?${queryString}`, true); } getApplication(id) { diff --git a/src/structures/MessageReaction.js b/src/structures/MessageReaction.js index 251bafcc0..be4f450e9 100644 --- a/src/structures/MessageReaction.js +++ b/src/structures/MessageReaction.js @@ -72,19 +72,20 @@ class MessageReaction { /** * Fetch all the users that gave this reaction. Resolves with a collection of users, mapped by their IDs. * @param {number} [limit=100] The maximum amount of users to fetch, defaults to 100 + * @param {Object} [options] Options to fetch users + * @param {Snowflake} [options.before] Limit fetching users to those with an id lower than the supplied id + * @param {Snowflake} [options.after] Limit fetching users to those with an id greater than the supplied id * @returns {Promise>} */ - fetchUsers(limit = 100) { + fetchUsers(limit = 100, { after, before } = {}) { const message = this.message; return message.client.rest.methods.getMessageReactionUsers( - message, this.emoji.identifier, limit + message, this.emoji.identifier, { after, before, limit } ).then(users => { - this.users = new Collection(); for (const rawUser of users) { const user = this.message.client.dataManager.newUser(rawUser); this.users.set(user.id, user); } - this.count = this.users.size; return this.users; }); } diff --git a/src/util/Constants.js b/src/util/Constants.js index 70f5947d2..e66304800 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -187,8 +187,8 @@ const Endpoints = exports.Endpoints = { toString: () => mbase, reactions: `${mbase}/reactions`, ack: `${mbase}/ack`, - Reaction: (emoji, limit) => { - const rbase = `${mbase}/reactions/${emoji}${limit ? `?limit=${limit}` : ''}`; + Reaction: emoji => { + const rbase = `${mbase}/reactions/${emoji}`; return { toString: () => rbase, User: userID => `${rbase}/${userID}`,