diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-09-17 13:33:51 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:54 +0100 |
commit | 0f4d849576812a249ee3497ddac7ffdc42f7f7b3 (patch) | |
tree | adbb6f9d72b4a2fd1d6d06e927cd76e3d6254ef5 | |
parent | f103563e404b3f4e3d24ed57834c2fe517c979d8 (diff) | |
download | wee-slack-0f4d849576812a249ee3497ddac7ffdc42f7f7b3.tar.gz |
Support typing notices for thread buffers
-rw-r--r-- | slack/slack_buffer.py | 12 | ||||
-rw-r--r-- | slack/slack_conversation.py | 41 | ||||
-rw-r--r-- | slack/slack_workspace.py | 2 |
3 files changed, 36 insertions, 19 deletions
diff --git a/slack/slack_buffer.py b/slack/slack_buffer.py index e5adb19..72e7814 100644 --- a/slack/slack_buffer.py +++ b/slack/slack_buffer.py @@ -240,18 +240,6 @@ class SlackBuffer(ABC): for message in self.messages.values(): await self.rerender_message(message) - async def typing_add_user(self, user_id: str, thread_ts: Optional[str]): - if not shared.config.look.typing_status_nicks: - return - - if not thread_ts: - user = await self.workspace.users[user_id] - weechat.hook_signal_send( - "typing_set_nick", - weechat.WEECHAT_HOOK_SIGNAL_STRING, - f"{self.buffer_pointer};typing;{user.nick()}", - ) - def set_typing_self(self): now = time.time() if now - 4 > self._typing_self_last_sent: diff --git a/slack/slack_conversation.py b/slack/slack_conversation.py index ef3583c..d6b0e88 100644 --- a/slack/slack_conversation.py +++ b/slack/slack_conversation.py @@ -22,6 +22,7 @@ if TYPE_CHECKING: SlackMessageReplied, SlackShRoomJoin, SlackShRoomUpdate, + SlackUserTyping, ) from typing_extensions import Literal @@ -361,13 +362,20 @@ class SlackConversation(SlackBuffer): await self.fetch_replies(message.thread_ts) if message.sender_user_id: - # TODO: thread buffers user = await self.workspace.users[message.sender_user_id] - weechat.hook_signal_send( - "typing_set_nick", - weechat.WEECHAT_HOOK_SIGNAL_STRING, - f"{self.buffer_pointer};off;{user.nick()}", - ) + if message.is_reply: + if parent_message and parent_message.thread_buffer: + weechat.hook_signal_send( + "typing_set_nick", + weechat.WEECHAT_HOOK_SIGNAL_STRING, + f"{parent_message.thread_buffer.buffer_pointer};off;{user.nick()}", + ) + else: + weechat.hook_signal_send( + "typing_set_nick", + weechat.WEECHAT_HOOK_SIGNAL_STRING, + f"{self.buffer_pointer};off;{user.nick()}", + ) async def change_message( self, data: Union[SlackMessageChanged, SlackMessageReplied] @@ -408,6 +416,27 @@ class SlackConversation(SlackBuffer): message.reaction_remove(reaction, user_id) await self.rerender_message(message) + async def typing_add_user(self, data: SlackUserTyping): + if not shared.config.look.typing_status_nicks: + return + + user = await self.workspace.users[data["user"]] + if "thread_ts" not in data: + weechat.hook_signal_send( + "typing_set_nick", + weechat.WEECHAT_HOOK_SIGNAL_STRING, + f"{self.buffer_pointer};typing;{user.nick()}", + ) + else: + thread_ts = SlackTs(data["thread_ts"]) + parent_message = self._messages.get(thread_ts) + if parent_message and parent_message.thread_buffer: + weechat.hook_signal_send( + "typing_set_nick", + weechat.WEECHAT_HOOK_SIGNAL_STRING, + f"{parent_message.thread_buffer.buffer_pointer};typing;{user.nick()}", + ) + async def open_thread(self, thread_hash: str, switch: bool = False): thread_ts = self.message_hashes.get_ts(thread_hash) if thread_ts: diff --git a/slack/slack_workspace.py b/slack/slack_workspace.py index 63417e8..8e61341 100644 --- a/slack/slack_workspace.py +++ b/slack/slack_workspace.py @@ -344,7 +344,7 @@ class SlackWorkspace: 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")) + await channel.typing_add_user(data) else: weechat.prnt("", f"\t{self.name} received: {json.dumps(data)}") except Exception as e: |