diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-08-25 18:16:47 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:54 +0100 |
commit | 425db0016edb859c13c0e5aede03a469cfcb47ed (patch) | |
tree | a832f772c1cbd8bf9fd487b507e196e04a7131ee /slack | |
parent | 74b6bf4a8117b446907e45a88fe2e7f06ece29db (diff) | |
download | wee-slack-425db0016edb859c13c0e5aede03a469cfcb47ed.tar.gz |
Support rendering huddles
Diffstat (limited to 'slack')
-rw-r--r-- | slack/slack_conversation.py | 18 | ||||
-rw-r--r-- | slack/slack_message.py | 23 | ||||
-rw-r--r-- | slack/slack_workspace.py | 4 |
3 files changed, 43 insertions, 2 deletions
diff --git a/slack/slack_conversation.py b/slack/slack_conversation.py index 211d156..01a1fc8 100644 --- a/slack/slack_conversation.py +++ b/slack/slack_conversation.py @@ -3,7 +3,7 @@ from __future__ import annotations import time from collections import OrderedDict from contextlib import contextmanager -from typing import TYPE_CHECKING, List, Optional +from typing import TYPE_CHECKING, List, Optional, Union import weechat @@ -14,7 +14,12 @@ from slack.util import get_callback_name if TYPE_CHECKING: from slack_api.slack_conversations_info import SlackConversationsInfo - from slack_rtm.slack_rtm_message import SlackMessageChanged, SlackMessageDeleted + from slack_rtm.slack_rtm_message import ( + SlackMessageChanged, + SlackMessageDeleted, + SlackShRoomJoin, + SlackShRoomUpdate, + ) from typing_extensions import Literal from slack.slack_api import SlackApi @@ -399,6 +404,15 @@ class SlackConversation: message.deleted = True await self.rerender_message(message) + async def update_message_room( + self, data: Union[SlackShRoomJoin, SlackShRoomUpdate] + ): + ts = SlackTs(data["room"]["thread_root_ts"]) + message = self._messages.get(ts) + if message: + message.update_message_json_room(data["room"]) + await self.rerender_message(message) + async def reaction_add(self, message_ts: SlackTs, reaction: str, user_id: str): message = self._messages.get(message_ts) if message: diff --git a/slack/slack_message.py b/slack/slack_message.py index 94f0501..d9c1715 100644 --- a/slack/slack_message.py +++ b/slack/slack_message.py @@ -29,6 +29,7 @@ if TYPE_CHECKING: SlackMessageBlockRichTextList, SlackMessageBlockRichTextSection, SlackMessageReaction, + SlackMessageSubtypeHuddleThreadRoom, ) from typing_extensions import assert_never @@ -140,6 +141,11 @@ class SlackMessage: self._rendered_prefix = None self._rendered_message = None + def update_message_json_room(self, room: SlackMessageSubtypeHuddleThreadRoom): + if "room" in self._message_json: + self._message_json["room"] = room + self._rendered_message = None + def _get_reaction(self, reaction_name: str): for reaction in self._message_json.get("reactions", []): if reaction["name"] == reaction_name: @@ -285,6 +291,23 @@ class SlackMessage: return f"{await self._nick()} {text_action} {text_conversation_name}{inviter_text}" + elif ( + "subtype" in self._message_json + and self._message_json["subtype"] == "huddle_thread" + ): + room = self._message_json["room"] + team = self._message_json["team"] + + huddle_text = "Huddle started" if not room["has_ended"] else "Huddle ended" + name_text = f", name: {room['name']}" if room["name"] else "" + texts: List[str] = [huddle_text + name_text] + + for channel_id in room["channels"]: + texts.append( + f"https://app.slack.com/client/{team}/{channel_id}?open=start_huddle" + ) + return "\n".join(texts) + else: if "blocks" in self._message_json: texts = await self._render_blocks(self._message_json["blocks"]) diff --git a/slack/slack_workspace.py b/slack/slack_workspace.py index b730987..ad36c3d 100644 --- a/slack/slack_workspace.py +++ b/slack/slack_workspace.py @@ -277,6 +277,8 @@ class SlackWorkspace: return elif data["type"] == "reaction_added" or data["type"] == "reaction_removed": channel_id = data["item"]["channel"] + elif data["type"] == "sh_room_join" or data["type"] == "sh_room_update": + channel_id = data["huddle"]["channel_id"] elif "channel" in data and type(data["channel"]) == str: channel_id = data["channel"] else: @@ -311,6 +313,8 @@ class SlackWorkspace: await channel.reaction_remove( SlackTs(data["item"]["ts"]), data["reaction"], data["user"] ) + elif data["type"] == "sh_room_join" or data["type"] == "sh_room_update": + await channel.update_message_room(data) elif data["type"] == "user_typing": await channel.typing_add_user(data["user"], data.get("thread_ts")) else: |