diff options
Diffstat (limited to 'slack/slack_thread.py')
-rw-r--r-- | slack/slack_thread.py | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/slack/slack_thread.py b/slack/slack_thread.py index bc02c26..79ef68c 100644 --- a/slack/slack_thread.py +++ b/slack/slack_thread.py @@ -51,32 +51,41 @@ class SlackThread(SlackBuffer): } async def buffer_switched_to(self): + await super().buffer_switched_to() await self.fill_history() - async def print_history(self): - if self.history_filled: - return - - self.history_filled = True + async def set_hotlist(self): + self.history_needs_refresh = True + await self.fill_history() - with self.loading(): - messages = chain([self.parent], self.parent.replies.values()) - for message in messages: + async def print_history(self): + messages = chain([self.parent], self.parent.replies.values()) + self.history_pending_messages.clear() + for message in list(messages): + if self.last_printed_ts is None or message.ts > self.last_printed_ts: await self.print_message(message) + while self.history_pending_messages: + message = self.history_pending_messages.pop(0) + await self.print_message(message) + async def fill_history(self): if self.history_pending: return - if self.parent.reply_history_filled: - await self.print_history() - return - with self.loading(): self.history_pending = True + if self.parent.reply_history_filled and not self.history_needs_refresh: + await self.print_history() + self.history_pending = False + return + messages = await self.parent.conversation.fetch_replies(self.parent.ts) + if self.history_needs_refresh: + await self.rerender_history() + sender_user_ids = [m.sender_user_id for m in messages if m.sender_user_id] self.workspace.users.initialize_items(sender_user_ids) @@ -90,6 +99,7 @@ class SlackThread(SlackBuffer): await gather(*(message.render(self.context) for message in messages)) await self.print_history() + self.history_needs_refresh = False self.history_pending = False async def mark_read(self): |