From 2476af055571888c90cbfa04e8bb9da129b13eae Mon Sep 17 00:00:00 2001 From: gryf Date: Sun, 20 Nov 2016 15:13:47 +0100 Subject: [PATCH] Adjusted get_history method --- slack_backup/client.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/slack_backup/client.py b/slack_backup/client.py index 91afc4a..9e62934 100644 --- a/slack_backup/client.py +++ b/slack_backup/client.py @@ -27,28 +27,35 @@ class Client(object): else: selected_channels = channels - self._update_users() - for channel in selected_channels: - # history = [] - latest = 'now' + history = [] + latest = 0 while True: messages, latest = self._get_channel_history(channel, latest) # TODO: merge messages witihn a channel - if not messages: + if latest is None: break + for msg in messages: + history.append(msg) self.session.close() + return history def _get_channel_history(self, channel, latest='now'): - result = self.slack.api_call("channels.history", channel=channel._id, - count=1000, latest=latest) + result = self.slack.api_call("channels.history", + channel=channel.slackid, count=1000, + latest=latest) if not result.get("ok"): logging.error(result['error']) return None, None + if result['messages']: + return result['messages'], result['messages'][-1]['ts'] + else: + return result['messages'], None + def _get_channel_list(self): result = self.slack.api_call("channels.list")