diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-08-20 12:10:28 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:53 +0100 |
commit | b4c1ebeead35f84d50dee33a9bf6d314a84a3d86 (patch) | |
tree | 47e07e1c04d360168812d47f6dd3703eaa6456bd /slack/slack_workspace.py | |
parent | 4e38811c1a97ed4217b8cf38aa0f82816e9f8513 (diff) | |
download | wee-slack-b4c1ebeead35f84d50dee33a9bf6d314a84a3d86.tar.gz |
Support sending and receiving typing
This does not support globally showing typing from direct messages, like
the old wee-slack did, because that's not supported by WeeChats typing
plugin. It only shows typing in the current buffer.
Diffstat (limited to 'slack/slack_workspace.py')
-rw-r--r-- | slack/slack_workspace.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/slack/slack_workspace.py b/slack/slack_workspace.py index 7e001a9..0d9405f 100644 --- a/slack/slack_workspace.py +++ b/slack/slack_workspace.py @@ -273,6 +273,12 @@ class SlackWorkspace: async def _ws_recv(self, data: SlackRtmMessage): try: + channel_id = "channel" in data and data["channel"] + if channel_id in self.open_conversations: + channel = self.open_conversations[channel_id] + else: + channel = None + if data["type"] == "message": if "subtype" in data and data["subtype"] == "message_changed": pass @@ -281,11 +287,12 @@ class SlackWorkspace: elif "subtype" in data and data["subtype"] == "message_replied": pass else: - channel_id = data["channel"] - if channel_id in self.open_conversations: - channel = self.open_conversations[channel_id] + if channel: message = SlackMessage(channel, data) await channel.add_message(message) + elif data["type"] == "user_typing": + if channel: + await channel.typing_add_user(data["user"], data.get("thread_ts")) else: weechat.prnt("", f"\t{self.name} received: {json.dumps(data)}") except Exception as e: @@ -304,6 +311,14 @@ class SlackWorkspace: print("lost connection on ping, reconnecting") run_async(self.reconnect()) + def send_typing(self, conversation_id: str): + if not self.is_connected: + raise SlackError(self, "Can't send typing when not connected") + if self._ws is None: + raise SlackError(self, "is_connected is True while _ws is None") + msg = {"type": "typing", "channel": conversation_id} + self._ws.send(json.dumps(msg)) + async def reconnect(self): self.disconnect() await self.connect() |