aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-10-15 23:15:54 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:54 +0100
commitfdc62f23df3eb715e921fc6f32d3a39aaf210a4e (patch)
tree45ffefd52652a3c67850d3cc25b0285a588b372e
parent0e4ac01dfd41a15eeb67de08ca788e82d3736a6f (diff)
downloadwee-slack-fdc62f23df3eb715e921fc6f32d3a39aaf210a4e.tar.gz
Show conversation topic in buffer title
-rw-r--r--slack/slack_conversation.py14
-rw-r--r--slack/slack_workspace.py3
-rw-r--r--typings/slack_api/slack_conversations_history.pyi10
-rw-r--r--typings/slack_api/slack_conversations_info.pyi3
-rw-r--r--typings/slack_rtm/slack_rtm_message.pyi8
5 files changed, 35 insertions, 3 deletions
diff --git a/slack/slack_conversation.py b/slack/slack_conversation.py
index d16655a..257796a 100644
--- a/slack/slack_conversation.py
+++ b/slack/slack_conversation.py
@@ -20,7 +20,7 @@ from slack.slack_message import (
from slack.slack_thread import SlackThread
from slack.slack_user import SlackBot, SlackUser, nick_color
from slack.task import gather, run_async
-from slack.util import with_color
+from slack.util import unhtmlescape, with_color
if TYPE_CHECKING:
from slack_api.slack_conversations_info import SlackConversationsInfo
@@ -248,6 +248,16 @@ class SlackConversation(SlackBuffer):
return True
return False
+ def buffer_title(self) -> str:
+ # TODO: unfurl and apply styles
+ return unhtmlescape(self._info.get("topic", {}).get("value", ""))
+
+ async def set_topic(self, title: str):
+ if "topic" not in self._info:
+ self._info["topic"] = {"value": "", "creator": "", "last_set": 0}
+ self._info["topic"]["value"] = title
+ await self.update_buffer_props()
+
async def get_name_and_buffer_props(self) -> Tuple[str, Dict[str, str]]:
name_without_prefix = await self.name()
name = f"{self.name_prefix('full_name')}{name_without_prefix}"
@@ -259,7 +269,7 @@ class SlackConversation(SlackBuffer):
return name, {
"short_name": short_name,
- "title": "topic",
+ "title": self.buffer_title(),
"input_multiline": "1",
"nicklist": "0" if self.type == "im" else "1",
"nicklist_display_groups": "0",
diff --git a/slack/slack_workspace.py b/slack/slack_workspace.py
index 8c0f9a6..eb26b8e 100644
--- a/slack/slack_workspace.py
+++ b/slack/slack_workspace.py
@@ -375,6 +375,9 @@ class SlackWorkspace:
elif "subtype" in data and data["subtype"] == "message_replied":
await channel.change_message(data)
else:
+ if "subtype" in data and data["subtype"] == "channel_topic":
+ await channel.set_topic(data["topic"])
+
message = SlackMessage(channel, data)
await channel.add_new_message(message)
elif data["type"] == "reaction_added" and data["item"]["type"] == "message":
diff --git a/typings/slack_api/slack_conversations_history.pyi b/typings/slack_api/slack_conversations_history.pyi
index 4b3702a..7443a14 100644
--- a/typings/slack_api/slack_conversations_history.pyi
+++ b/typings/slack_api/slack_conversations_history.pyi
@@ -456,6 +456,15 @@ class SlackMessageSubtypeChannelLeave(SlackMessageCommon):
class SlackMessageSubtypeChannelLeaveFinal(SlackMessageSubtypeChannelLeave):
pass
+class SlackMessageSubtypeChannelTopic(SlackMessageCommon):
+ subtype: Literal["channel_topic"]
+ topic: str
+ user: str
+
+@final
+class SlackMessageSubtypeChannelTopicFinal(SlackMessageSubtypeChannelTopic):
+ pass
+
SlackMessage = (
SlackMessageStandardFinal
| SlackMessageMeFinal
@@ -470,6 +479,7 @@ SlackMessage = (
| SlackMessageSubtypeBotAddFinal
| SlackMessageSubtypeChannelJoinFinal
| SlackMessageSubtypeChannelLeaveFinal
+ | SlackMessageSubtypeChannelTopicFinal
| SlackMessageRtm
)
diff --git a/typings/slack_api/slack_conversations_info.pyi b/typings/slack_api/slack_conversations_info.pyi
index ff42626..7566951 100644
--- a/typings/slack_api/slack_conversations_info.pyi
+++ b/typings/slack_api/slack_conversations_info.pyi
@@ -4,7 +4,7 @@ from typing import Generic, List, TypeVar
from slack_api.slack_common import SlackErrorResponse
from slack_api.slack_conversations_history import SlackMessage
-from typing_extensions import Literal, TypedDict, final
+from typing_extensions import Literal, NotRequired, TypedDict, final
T = TypeVar("T")
@@ -76,6 +76,7 @@ class SlackConversationsInfoIm(SlackConversationsInfoCommon):
unread_count_display: int
is_open: bool
priority: int
+ topic: NotRequired[SlackTopic]
SlackConversationsInfoNotIm = (
SlackConversationsInfoPublic
diff --git a/typings/slack_rtm/slack_rtm_message.pyi b/typings/slack_rtm/slack_rtm_message.pyi
index 709f4a5..efb9e6b 100644
--- a/typings/slack_rtm/slack_rtm_message.pyi
+++ b/typings/slack_rtm/slack_rtm_message.pyi
@@ -7,6 +7,7 @@ from slack_api.slack_conversations_history import (
SlackMessageSubtypeBotRemove,
SlackMessageSubtypeChannelJoin,
SlackMessageSubtypeChannelLeave,
+ SlackMessageSubtypeChannelTopic,
SlackMessageSubtypeHuddleThread,
SlackMessageSubtypeHuddleThreadRoom,
SlackMessageThreadBroadcast,
@@ -87,6 +88,12 @@ class SlackMessageSubtypeChannelLeaveRtm(SlackMessageSubtypeChannelLeave):
channel: str
@final
+class SlackMessageSubtypeChannelTopicRtm(SlackMessageSubtypeChannelTopic):
+ channel: str
+ team: str
+ event_ts: str
+
+@final
class SlackMessageChanged(TypedDict):
type: Literal["message"]
subtype: Literal["message_changed"]
@@ -259,6 +266,7 @@ SlackMessageRtm = (
| SlackMessageSubtypeBotAddRtm
| SlackMessageSubtypeChannelJoinRtm
| SlackMessageSubtypeChannelLeaveRtm
+ | SlackMessageSubtypeChannelTopicRtm
)
SlackRtmMessage = (