diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-07-11 01:07:10 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:53 +0100 |
commit | e6afe041876394a6f75cbb3e8671faa3dd91b0cc (patch) | |
tree | 1f43efb24d26455c553db7440e9910664b12be31 /slack/slack_conversation.py | |
parent | 675d28844004a1acb3bb573c52f69efe5e094f07 (diff) | |
download | wee-slack-e6afe041876394a6f75cbb3e8671faa3dd91b0cc.tar.gz |
Show correct date/time for messages
Diffstat (limited to 'slack/slack_conversation.py')
-rw-r--r-- | slack/slack_conversation.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/slack/slack_conversation.py b/slack/slack_conversation.py index e4504cd..1e8728d 100644 --- a/slack/slack_conversation.py +++ b/slack/slack_conversation.py @@ -8,7 +8,7 @@ from typing import TYPE_CHECKING, List, Optional import weechat from slack.shared import shared -from slack.slack_message import SlackMessage +from slack.slack_message import SlackMessage, SlackTs from slack.task import gather from slack.util import get_callback_name @@ -39,7 +39,7 @@ class SlackConversation: self.workspace = workspace self._info = info self._members: Optional[List[str]] = None - self._messages: OrderedDict[str, SlackMessage] = OrderedDict() + self._messages: OrderedDict[SlackTs, SlackMessage] = OrderedDict() # TODO: buffer_pointer may be accessed by buffer_switch before it's initialized self.buffer_pointer: str = "" self.is_loading = False @@ -162,12 +162,10 @@ class SlackConversation: sender_user_ids = [m.sender_user_id for m in messages if m.sender_user_id] await self.workspace.users.initialize_items(sender_user_ids) - messages_rendered = await gather( - *(message.render_message() for message in messages) - ) + await gather(*(message.render() for message in messages)) - for rendered in reversed(messages_rendered): - weechat.prnt(self.buffer_pointer, rendered) + for message in reversed(messages): + self.print_message(message, await message.render()) print(f"history w/o fetch took: {time.time() - start}") self.history_filled = True @@ -176,13 +174,16 @@ class SlackConversation: async def add_message(self, message: SlackMessage): self._messages[message.ts] = message if self.history_filled: - message_rendered = await message.render_message() - weechat.prnt(self.buffer_pointer, message_rendered) + rendered = await message.render() + self.print_message(message, rendered) else: weechat.buffer_set( self.buffer_pointer, "hotlist", str(message.priority.value) ) + def print_message(self, message: SlackMessage, rendered: str): + weechat.prnt_date_tags(self.buffer_pointer, message.ts.major, "", rendered) + def _buffer_input_cb(self, data: str, buffer: str, input_data: str) -> int: weechat.prnt(buffer, "Text: %s" % input_data) return weechat.WEECHAT_RC_OK |