aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--slack/slack_buffer.py4
-rw-r--r--slack/slack_conversation.py14
-rw-r--r--slack/slack_message.py9
-rw-r--r--slack/slack_thread.py6
-rw-r--r--slack/slack_workspace.py4
5 files changed, 29 insertions, 8 deletions
diff --git a/slack/slack_buffer.py b/slack/slack_buffer.py
index 3da8aad..881e56d 100644
--- a/slack/slack_buffer.py
+++ b/slack/slack_buffer.py
@@ -178,7 +178,7 @@ class SlackBuffer(ABC):
@property
@abstractmethod
- def last_read(self) -> SlackTs:
+ def last_read(self) -> Optional[SlackTs]:
raise NotImplementedError()
@abstractmethod
@@ -253,7 +253,7 @@ class SlackBuffer(ABC):
async def print_message(self, message: SlackMessage):
rendered = await message.render(self.context)
- backlog = message.ts <= self.last_read
+ backlog = self.last_read is not None and message.ts <= self.last_read
tags = await message.tags(backlog)
weechat.prnt_date_tags(self.buffer_pointer, message.ts.major, tags, rendered)
if backlog:
diff --git a/slack/slack_conversation.py b/slack/slack_conversation.py
index 5870052..cd0492f 100644
--- a/slack/slack_conversation.py
+++ b/slack/slack_conversation.py
@@ -290,6 +290,20 @@ class SlackConversation(SlackBuffer):
parent_message.reply_history_filled = True
return replies
+ async def set_hotlist(self):
+ history = await self._api.fetch_conversations_history(self)
+ if self.buffer_pointer and shared.current_buffer_pointer != self.buffer_pointer:
+ for message_json in history["messages"]:
+ message = SlackMessage(self, message_json)
+ if message.ts > self.last_read or (
+ self.display_thread_replies()
+ and message.latest_reply
+ and message.latest_reply > message.last_read
+ ):
+ weechat.buffer_set(
+ self.buffer_pointer, "hotlist", message.priority.value
+ )
+
async def fill_history(self):
if self.history_filled or self.history_pending:
return
diff --git a/slack/slack_message.py b/slack/slack_message.py
index 2eb1bc7..0335c67 100644
--- a/slack/slack_message.py
+++ b/slack/slack_message.py
@@ -195,11 +195,9 @@ class SlackMessage:
return self.conversation.messages.get(self.thread_ts)
@property
- def last_read(self) -> SlackTs:
+ def last_read(self) -> Optional[SlackTs]:
if "last_read" in self._message_json:
return SlackTs(self._message_json["last_read"])
- else:
- return SlackTs("0.0")
@last_read.setter
def last_read(self, value: SlackTs):
@@ -213,6 +211,11 @@ class SlackMessage:
)
@property
+ def latest_reply(self) -> Optional[SlackTs]:
+ if "latest_reply" in self._message_json:
+ return SlackTs(self._message_json["latest_reply"])
+
+ @property
def is_bot_message(self) -> bool:
return (
"subtype" in self._message_json
diff --git a/slack/slack_thread.py b/slack/slack_thread.py
index 24bdc66..bc02c26 100644
--- a/slack/slack_thread.py
+++ b/slack/slack_thread.py
@@ -1,7 +1,7 @@
from __future__ import annotations
from itertools import chain
-from typing import TYPE_CHECKING, Dict, Mapping, Tuple
+from typing import TYPE_CHECKING, Dict, Mapping, Optional, Tuple
from slack.slack_buffer import SlackBuffer
from slack.slack_message import SlackMessage, SlackTs
@@ -31,7 +31,7 @@ class SlackThread(SlackBuffer):
return self.parent.replies
@property
- def last_read(self) -> SlackTs:
+ def last_read(self) -> Optional[SlackTs]:
return self.parent.last_read
async def get_name_and_buffer_props(self) -> Tuple[str, Dict[str, str]]:
@@ -98,7 +98,7 @@ class SlackThread(SlackBuffer):
return
# last_read can only be set if it exists (which is on threads you're subscribed to)
- if self.last_read == SlackTs("0.0"):
+ if self.last_read is None:
return
last_read_line_ts = self.last_read_line_ts()
diff --git a/slack/slack_workspace.py b/slack/slack_workspace.py
index f202a86..3f5d525 100644
--- a/slack/slack_workspace.py
+++ b/slack/slack_workspace.py
@@ -264,6 +264,10 @@ class SlackWorkspace:
for _, conversation in sorted(conversations_to_open):
await conversation.open_buffer()
+ await gather(
+ *(conversation[1].set_hotlist() for conversation in conversations_to_open)
+ )
+
self.is_connected = True
async def _conversation_if_should_open(self, info: SlackUsersConversations):