Skip to content

Commit

Permalink
Added support for Reaction:getUsers query
Browse files Browse the repository at this point in the history
  • Loading branch information
SinisterRectus committed Oct 23, 2017
1 parent a090a7e commit b9b181d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions libs/client/API.lua
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ function API:deleteUserReaction(channel_id, message_id, emoji, user_id) -- Messa
return self:request("DELETE", endpoint)
end

function API:getReactions(channel_id, message_id, emoji) -- Reaction:getUsers
function API:getReactions(channel_id, message_id, emoji, query) -- Reaction:getUsers
local endpoint = f(endpoints.CHANNEL_MESSAGE_REACTION, channel_id, message_id, emoji)
return self:request("GET", endpoint)
return self:request("GET", endpoint, nil, query)
end

function API:deleteAllReactions(channel_id, message_id) -- Message:clearReactions
Expand Down
18 changes: 16 additions & 2 deletions libs/containers/Reaction.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,32 @@ function Reaction:__hash()
return self._emoji_id or self._emoji_name
end

function Reaction:getUsers()
local function getUsers(self, query)
local emoji = Resolver.emoji(self)
local message = self._parent
local channel = message._parent
local data, err = self.client._api:getReactions(channel._id, message._id, emoji)
local data, err = self.client._api:getReactions(channel._id, message._id, emoji, query)
if data then
return SecondaryCache(data, self.client._users)
else
return nil, err
end
end

function Reaction:getUsers(limit)
return getUsers(self, limit and {limit = limit})
end

function Reaction:getUsersBefore(id, limit)
id = Resolver.userId(id)
return getUsers(self, {before = id, limit = limit})
end

function Reaction:getUsersAfter(id, limit)
id = Resolver.userId(id)
return getUsers(self, {after = id, limit = limit})
end

function Reaction:delete(id)
return self._parent:removeReaction(self, id)
end
Expand Down

0 comments on commit b9b181d

Please sign in to comment.