aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-10-19 22:43:01 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:54 +0100
commit84c0c20bd5bf04b89384691d90c9ef7f2a41ca0c (patch)
treea2ba5711d5fab1777f5b18971517dd5ecc7720bf
parent014127990d651d4108c07db265dcc79d42eb2e5b (diff)
downloadwee-slack-84c0c20bd5bf04b89384691d90c9ef7f2a41ca0c.tar.gz
Close IM/MPIM and remove from open_conversations on buffer close
-rw-r--r--slack/slack_api.py8
-rw-r--r--slack/slack_conversation.py11
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