Skip to content

Commit

Permalink
Replace deprecated channels.list call
Browse files Browse the repository at this point in the history
Fix case where channels_lists could be uninitialized.
Fix case where channels_lists could be left empty if the first call was
made without a wa_token.
  • Loading branch information
Urth committed Apr 16, 2021
1 parent 051d289 commit 8363abd
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@

# API URLs
WA_USERS_LIST = 'https://slack.com/api/users.list?token=%(wa_token)s'
WA_CHANNELS_LIST = ('https://slack.com/api/channels.list?token=%(wa_token)s&'
'exclude_archived=1')
WA_CHANNELS_LIST = ('https://slack.com/api/conversations.list?'
'token=%(wa_token)s&exclude_archived=1&limit=1000')

# Other
UNSET = '<unset>'
Expand Down Expand Up @@ -461,10 +461,10 @@ def incomingwh_post(cls, url, payload, failure_callback=None):
def get_users_list(self, owh_token, wa_token):
# Check if we have the list already.
# TODO: this is now infinitely cached, not nice
if not wa_token:
self.users_lists[owh_token] = {}

if owh_token not in self.users_lists:
if not wa_token:
return {}

self.log.info('Fetching users.list for %s...', owh_token)
url = WA_USERS_LIST % {'wa_token': wa_token}
try:
Expand Down Expand Up @@ -494,16 +494,17 @@ def get_users_list(self, owh_token, wa_token):
else:
self.log.error(
'Fetching users.list failed: %s', data['error'])
self.users_lists[owh_token] = {}

return self.users_lists[owh_token]

def get_channels_list(self, owh_token, wa_token):
# Check if we have the list already.
# TODO: this is now infinitely cached, not nice
if not wa_token:
self.channels_lists[owh_token] = {}

if owh_token not in self.channels_lists:
if not wa_token:
return {}

self.log.info('Fetching channels.list for %s...', owh_token)
url = WA_CHANNELS_LIST % {'wa_token': wa_token}
try:
Expand Down Expand Up @@ -531,6 +532,7 @@ def get_channels_list(self, owh_token, wa_token):
else:
self.log.error(
'Fetching channels.list failed: %s', data['error'])
self.channels_lists[owh_token] = {}

return self.channels_lists[owh_token]

Expand Down

0 comments on commit 8363abd

Please sign in to comment.