Skip to content

Commit

Permalink
add conversations.members pagination handling
Browse files Browse the repository at this point in the history
  • Loading branch information
David Lovitch committed Jan 14, 2021
1 parent da4b736 commit eecb372
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion slacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,31 @@ def get_channel_members_ids(self, channel_name):
"""
returns an array of member IDs for channel_name
"""
return self.get_channel_info(channel_name)['members']
cid = self.get_channelid(channel_name)
members = []

url_template = self.url + "conversations.members?token={}&channel={}"
url = url_template.format(self.token, cid)

while True:
ret = self.get_with_retry_to_json(url)
if ret['ok'] is not True:
m = "Attempted get_channel_members_ids() for {}, but return was {}"
m = m.format(channel_name, ret)
raise RuntimeError(m)

# append members to the end of the existing members list
members += ret['members']

# once through the loop once, update the url to call to include the cursor
if ret['response_metadata']['next_cursor']:
url_template = self.url + "conversations.members?token={}&channel={}&cursor={}"
url = url_template.format(self.token, cid, ret['response_metadata']['next_cursor'])
# no more members to iterate over
else:
break

return members

def channel_has_only_restricted_members(self, channel_name):
"""
Expand Down

0 comments on commit eecb372

Please sign in to comment.