diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2020-04-20 00:17:29 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2020-05-30 21:11:27 +0200 |
commit | ae81365066227a484ca0c5daba092047cb6062b5 (patch) | |
tree | 04feee1cfa94141aef51c3640c67b184b2eaabd3 /wee_slack.py | |
parent | df0336ae16eff73faea8ecc9e5ee375b558c4e42 (diff) | |
download | wee-slack-ae81365066227a484ca0c5daba092047cb6062b5.tar.gz |
Support getting only new messages in get_history
This is useful to only get new messages after we reconnect to the
websocket, instead of loading the whole history again.
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/wee_slack.py b/wee_slack.py index 50d9917..b97b1d4 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -1955,16 +1955,22 @@ class SlackChannel(SlackChannelCommon): return w.buffer_get_integer(self.channel_buffer, "hidden") == 0 def get_history(self, slow_queue=False): - if not self.got_history: - w.prnt_date_tags(self.channel_buffer, SlackTS().major, - tag(backlog=True, no_log=True), '\tgetting channel history...') - s = SlackRequest(self.team, self.team.slack_api_translator[self.type]["history"], - {"channel": self.identifier, "count": BACKLOG_SIZE}, channel=self, metadata={'clear': True}) - if not slow_queue: - self.eventrouter.receive(s) - else: - self.eventrouter.receive_slow(s) - self.got_history = True + post_data = {"channel": self.identifier, "count": BACKLOG_SIZE} + if self.got_history and self.messages: + post_data["oldest"] = next(reversed(self.messages)) + clear = False + else: + clear = True + + w.prnt_date_tags(self.channel_buffer, SlackTS().major, + tag(backlog=True, no_log=True), '\tgetting channel history...') + s = SlackRequest(self.team, self.team.slack_api_translator[self.type]["history"], + post_data, channel=self, metadata={'clear': clear}) + if not slow_queue: + self.eventrouter.receive(s) + else: + self.eventrouter.receive_slow(s) + self.got_history = True def main_message_keys_reversed(self): return (key for key in reversed(self.messages) @@ -2836,6 +2842,8 @@ def handle_mpimopen(mpim_json, eventrouter, team, channel, metadata, object_name def handle_history(message_json, eventrouter, team, channel, metadata): if metadata['clear']: channel.clear_messages() + else: + channel.reprint_messages() channel.got_history = True for message in reversed(message_json["messages"]): process_message(message, eventrouter, team, channel, metadata, history_message=True) |