diff options
-rw-r--r-- | slack/slack_api.py | 8 | ||||
-rw-r--r-- | slack/slack_conversation.py | 11 |
2 files changed, 19 insertions, 0 deletions
diff --git a/slack/slack_api.py b/slack/slack_api.py index 2264e36..c82fc5b 100644 --- a/slack/slack_api.py +++ b/slack/slack_api.py @@ -276,6 +276,14 @@ class SlackApi(SlackApiCommon): raise SlackApiError(self.workspace, method, response) return response + async def conversations_close(self, conversation: SlackConversation): + method = "conversations.close" + 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_conversation.py b/slack/slack_conversation.py index 351d24d..e415dd4 100644 --- a/slack/slack_conversation.py +++ b/slack/slack_conversation.py @@ -687,3 +687,14 @@ class SlackConversation(SlackBuffer): async def post_message(self, text: str) -> None: await self._api.chat_post_message(self.conversation, text) + + async def _buffer_closed(self): + if self.id in self.workspace.open_conversations: + del self.workspace.open_conversations[self.id] + if self.type in ["im", "mpim"]: + await self._api.conversations_close(self) + + def _buffer_close_cb(self, data: str, buffer: str) -> int: + super()._buffer_close_cb(data, buffer) + run_async(self._buffer_closed()) + return weechat.WEECHAT_RC_OK |