aboutsummaryrefslogtreecommitdiffstats
path: root/slack/slack_message.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-08-26 21:00:07 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:54 +0100
commit4b68e8721d18f83c58fea5109da95346363bb9e8 (patch)
tree540d5bbe9995dd114f0d05d0a024197e9d1e34a1 /slack/slack_message.py
parent6722517e91c19cc7c1d39335a1b64020ac7c0b9b (diff)
downloadwee-slack-4b68e8721d18f83c58fea5109da95346363bb9e8.tar.gz
Support showing thread replies in the channel
Diffstat (limited to 'slack/slack_message.py')
-rw-r--r--slack/slack_message.py34
1 files changed, 33 insertions, 1 deletions
diff --git a/slack/slack_message.py b/slack/slack_message.py
index 3537e1d..1d61950 100644
--- a/slack/slack_message.py
+++ b/slack/slack_message.py
@@ -107,6 +107,7 @@ class SlackMessage:
self._rendered_message = None
self.conversation = conversation
self.ts = SlackTs(message_json["ts"])
+ self.replies: List[SlackMessage] = []
self._deleted = False
@property
@@ -118,6 +119,28 @@ class SlackMessage:
return self.conversation.message_hashes[self.ts]
@property
+ def thread_ts(self) -> Optional[SlackTs]:
+ return (
+ SlackTs(self._message_json["thread_ts"])
+ if "thread_ts" in self._message_json
+ else None
+ )
+
+ @property
+ def is_thread_parent(self) -> bool:
+ return self.thread_ts == self.ts
+
+ @property
+ def is_reply(self) -> bool:
+ return self.thread_ts is not None and not self.is_thread_parent
+
+ @property
+ def parent_message(self) -> Optional[SlackMessage]:
+ if not self.is_reply or self.thread_ts is None:
+ return None
+ return self.conversation.get_message(self.thread_ts)
+
+ @property
def is_bot_message(self) -> bool:
return (
"subtype" in self._message_json
@@ -341,6 +364,7 @@ class SlackMessage:
if self._deleted:
return with_color(shared.config.color.deleted_message.value, "(deleted)")
else:
+ thread_prefix = self._create_thread_prefix()
text = await self._render_message_text()
text_edited = (
f" {with_color(shared.config.color.edited_message_suffix.value, '(edited)')}"
@@ -349,7 +373,7 @@ class SlackMessage:
)
reactions = await self._create_reactions_string()
thread = self._create_thread_string()
- return text + text_edited + reactions + thread
+ return thread_prefix + text + text_edited + reactions + thread
async def render_message(self, rerender: bool = False) -> str:
if self._rendered_message is not None and not rerender:
@@ -517,6 +541,14 @@ class SlackMessage:
else:
return ""
+ def _create_thread_prefix(self) -> str:
+ parent_message = self.parent_message
+ if not parent_message:
+ return ""
+
+ text = f"[{parent_message.hash}]"
+ return with_color(nick_color(str(parent_message.hash)), text) + " "
+
def _create_thread_string(self) -> str:
if "reply_count" not in self._message_json:
return ""