From 8363abdd1851500c35913162f310a616f541f23d Mon Sep 17 00:00:00 2001 From: Harm Geerts Date: Fri, 16 Apr 2021 14:40:03 +0200 Subject: [PATCH] Replace deprecated channels.list call 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. --- wsgi.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/wsgi.py b/wsgi.py index 297aed4..2618dc7 100644 --- a/wsgi.py +++ b/wsgi.py @@ -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 = '' @@ -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: @@ -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: @@ -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]