From 20fcca5f2ccbd7b524908d11d14a9ce8f33c2dd6 Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Thu, 19 Oct 2023 22:09:30 +0200 Subject: Show user status in DM buffer title --- slack/slack_conversation.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'slack/slack_conversation.py') diff --git a/slack/slack_conversation.py b/slack/slack_conversation.py index 257796a..351d24d 100644 --- a/slack/slack_conversation.py +++ b/slack/slack_conversation.py @@ -188,6 +188,11 @@ class SlackConversation(SlackBuffer): def muted(self) -> bool: return self.id in self.workspace.muted_channels + @property + def im_user_id(self) -> Optional[str]: + if self.type == "im": + return self._info.get("user") + async def sort_key(self) -> str: type_sort_key = { "channel": 0, @@ -248,9 +253,14 @@ class SlackConversation(SlackBuffer): return True return False - def buffer_title(self) -> str: + async def buffer_title(self) -> str: # TODO: unfurl and apply styles - return unhtmlescape(self._info.get("topic", {}).get("value", "")) + topic = unhtmlescape(self._info.get("topic", {}).get("value", "")) + if self.im_user_id: + user = await self.workspace.users[self.im_user_id] + status = f"{user.status_emoji} {user.status_text}".strip() + return " | ".join(part for part in [status, topic] if part) + return topic async def set_topic(self, title: str): if "topic" not in self._info: @@ -269,7 +279,7 @@ class SlackConversation(SlackBuffer): return name, { "short_name": short_name, - "title": self.buffer_title(), + "title": await self.buffer_title(), "input_multiline": "1", "nicklist": "0" if self.type == "im" else "1", "nicklist_display_groups": "0", -- cgit