diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-07-11 00:37:14 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:53 +0100 |
commit | 675d28844004a1acb3bb573c52f69efe5e094f07 (patch) | |
tree | 6e23fc5c9f98fbd3959d9fb65762ab7289dc9e11 /slack | |
parent | f522a1340e6d72f2e7090772379ff25aeb590bcf (diff) | |
download | wee-slack-675d28844004a1acb3bb573c52f69efe5e094f07.tar.gz |
Don't print message to buffer if history isn't printed
If new messages are printed before the history, they will remain at the
top of the buffer after the history is printed.
Diffstat (limited to 'slack')
-rw-r--r-- | slack/slack_conversation.py | 9 | ||||
-rw-r--r-- | slack/slack_message.py | 12 |
2 files changed, 19 insertions, 2 deletions
diff --git a/slack/slack_conversation.py b/slack/slack_conversation.py index 3b58e72..e4504cd 100644 --- a/slack/slack_conversation.py +++ b/slack/slack_conversation.py @@ -175,8 +175,13 @@ class SlackConversation: async def add_message(self, message: SlackMessage): self._messages[message.ts] = message - message_rendered = await message.render_message() - weechat.prnt(self.buffer_pointer, message_rendered) + if self.history_filled: + message_rendered = await message.render_message() + weechat.prnt(self.buffer_pointer, message_rendered) + else: + weechat.buffer_set( + self.buffer_pointer, "hotlist", str(message.priority.value) + ) def _buffer_input_cb(self, data: str, buffer: str, input_data: str) -> int: weechat.prnt(buffer, "Text: %s" % input_data) diff --git a/slack/slack_message.py b/slack/slack_message.py index dc7d79d..1a3365f 100644 --- a/slack/slack_message.py +++ b/slack/slack_message.py @@ -1,6 +1,7 @@ from __future__ import annotations import re +from enum import Enum from typing import TYPE_CHECKING, List, Match, Optional from slack.log import print_exception_once @@ -17,6 +18,13 @@ if TYPE_CHECKING: from slack.slack_workspace import SlackWorkspace +class MessagePriority(Enum): + LOW = 0 + MESSAGE = 1 + PRIVATE = 2 + HIGHLIGHT = 3 + + class SlackMessage: def __init__(self, conversation: SlackConversation, message_json: SlackMessageDict): self._message_json = message_json @@ -31,6 +39,10 @@ class SlackMessage: def sender_user_id(self) -> Optional[str]: return self._message_json.get("user") + @property + def priority(self) -> MessagePriority: + return MessagePriority.MESSAGE + async def render_message(self) -> str: prefix_coro = self._prefix() message_coro = self._unfurl_refs(self._message_json["text"]) |