From 8c814bea828b5cd9ed5de968383bef0aa169f0bc Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Sun, 10 Mar 2024 14:34:03 +0100 Subject: Replace use of history_pending with is_loading history_pending had a problem with being stuck as True if a crash occurred. Additionally, only is_loading is shown in the input bar item, so if only history_pending is True for some reason (which shouldn't happen), it's not shown. I don't think I need a separate variable, so instead of fixing history_pending, just use is_loading which doesn't have these problems. --- slack/slack_buffer.py | 1 - slack/slack_conversation.py | 9 +++------ slack/slack_thread.py | 6 +----- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/slack/slack_buffer.py b/slack/slack_buffer.py index 4c88d4c..4732521 100644 --- a/slack/slack_buffer.py +++ b/slack/slack_buffer.py @@ -152,7 +152,6 @@ class SlackBuffer(ABC): # TODO: buffer_pointer may be accessed by buffer_switch before it's initialized self.buffer_pointer: Optional[str] = None self.is_loading = False - self.history_pending = False self.history_pending_messages: List[SlackMessage] = [] self.history_needs_refresh = False self.last_printed_ts: Optional[SlackTs] = None diff --git a/slack/slack_conversation.py b/slack/slack_conversation.py index cf965da..d43624b 100644 --- a/slack/slack_conversation.py +++ b/slack/slack_conversation.py @@ -455,7 +455,7 @@ class SlackConversation(SlackBuffer): self.hotlist_tss.add(message.latest_reply) async def fill_history(self, update: bool = False): - if self.history_pending: + if self.is_loading: return if ( @@ -466,8 +466,6 @@ class SlackConversation(SlackBuffer): return with self.loading(): - self.history_pending = True - history_after_ts = ( next(iter(self._messages), None) if self.history_needs_refresh @@ -548,7 +546,6 @@ class SlackConversation(SlackBuffer): await self.print_message(message) self.history_needs_refresh = False - self.history_pending = False async def nicklist_update(self): if self.nicklist_needs_refresh and self.type != "im": @@ -615,7 +612,7 @@ class SlackConversation(SlackBuffer): self._messages[message.ts] = message if self.should_display_message(message): - if self.history_pending: + if self.is_loading: self.history_pending_messages.append(message) elif self.last_printed_ts is not None: await self.print_message(message) @@ -630,7 +627,7 @@ class SlackConversation(SlackBuffer): parent_message.replies[message.ts] = message thread_buffer = parent_message.thread_buffer if thread_buffer: - if thread_buffer.history_pending: + if thread_buffer.is_loading: thread_buffer.history_pending_messages.append(message) else: await thread_buffer.print_message(message) diff --git a/slack/slack_thread.py b/slack/slack_thread.py index fe86b23..62d02ed 100644 --- a/slack/slack_thread.py +++ b/slack/slack_thread.py @@ -103,15 +103,12 @@ class SlackThread(SlackBuffer): await self.print_message(message) async def fill_history(self): - if self.history_pending: + if self.is_loading: 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) @@ -133,7 +130,6 @@ class SlackThread(SlackBuffer): await self.print_history() self.history_needs_refresh = False - self.history_pending = False async def print_message(self, message: SlackMessage): did_print = await super().print_message(message) -- cgit