diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-09 18:51:05 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 13:01:40 +0100 |
commit | 32a4739bcd9fd3ef289b0f9c8bb0b4248d9444b6 (patch) | |
tree | a35af16926b13190391c821d32944593b91e7628 /slack | |
parent | 1b495a4b9ab7742c50de247efa9101b1eac08ef7 (diff) | |
download | wee-slack-32a4739bcd9fd3ef289b0f9c8bb0b4248d9444b6.tar.gz |
Add an option to leave the channel when a buffer is closed
Diffstat (limited to 'slack')
-rw-r--r-- | slack/config.py | 7 | ||||
-rw-r--r-- | slack/slack_api.py | 8 | ||||
-rw-r--r-- | slack/slack_buffer.py | 6 | ||||
-rw-r--r-- | slack/slack_conversation.py | 2 |
4 files changed, 22 insertions, 1 deletions
diff --git a/slack/config.py b/slack/config.py index 1bb4f0f..bf785ea 100644 --- a/slack/config.py +++ b/slack/config.py @@ -190,6 +190,13 @@ class SlackConfigSectionLook: "*", ) + self.leave_channel_on_buffer_close = WeeChatOption( + self._section, + "leave_channel_on_buffer_close", + "leave channel when a buffer is closed", + True, + ) + self.muted_conversations_notify: WeeChatOption[ Literal["none", "personal_highlights", "all_highlights", "all"] ] = WeeChatOption( diff --git a/slack/slack_api.py b/slack/slack_api.py index 8d49e55..cb4af1e 100644 --- a/slack/slack_api.py +++ b/slack/slack_api.py @@ -377,6 +377,14 @@ class SlackApi(SlackApiCommon): raise SlackApiError(self.workspace, method, response, params) return response + async def conversations_leave(self, conversation: SlackConversation): + method = "conversations.leave" + params: Params = {"channel": conversation.id} + response: SlackGenericResponse = await self._fetch(method, params) + if response["ok"] is False: + raise SlackApiError(self.workspace, method, response, params) + return response + async def conversations_mark(self, conversation: SlackConversation, ts: SlackTs): method = "conversations.mark" params: Params = {"channel": conversation.id, "ts": ts} diff --git a/slack/slack_buffer.py b/slack/slack_buffer.py index afb5282..761b9a3 100644 --- a/slack/slack_buffer.py +++ b/slack/slack_buffer.py @@ -530,7 +530,11 @@ class SlackBuffer(ABC): return weechat.WEECHAT_RC_OK def _buffer_close_cb(self, data: str, buffer: str) -> int: - run_async(self._buffer_close(update_server=True)) + run_async( + self._buffer_close( + update_server=shared.config.look.leave_channel_on_buffer_close.value + ) + ) return weechat.WEECHAT_RC_OK async def _buffer_close( diff --git a/slack/slack_conversation.py b/slack/slack_conversation.py index a87cb3f..1da093d 100644 --- a/slack/slack_conversation.py +++ b/slack/slack_conversation.py @@ -740,6 +740,8 @@ class SlackConversation(SlackBuffer): if update_server: if self.type in ["im", "mpim"]: await self._api.conversations_close(self) + else: + await self._api.conversations_leave(self) _T = TypeVar("_T", bound=SlackConversation) |