aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--slack/slack_buffer.py17
-rw-r--r--slack/slack_conversation.py20
-rw-r--r--slack/slack_workspace.py2
3 files changed, 27 insertions, 12 deletions
diff --git a/slack/slack_buffer.py b/slack/slack_buffer.py
index 13cfb1b..afb5282 100644
--- a/slack/slack_buffer.py
+++ b/slack/slack_buffer.py
@@ -272,6 +272,9 @@ class SlackBuffer(ABC):
if switch:
await self.buffer_switched_to()
+ async def close_buffer(self, update_server: bool = False):
+ await self._buffer_close(call_buffer_close=True, update_server=update_server)
+
def update_buffer_props(self) -> None:
if self.buffer_pointer is None:
return
@@ -527,11 +530,21 @@ 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))
+ return weechat.WEECHAT_RC_OK
+
+ async def _buffer_close(
+ self, call_buffer_close: bool = False, update_server: bool = False
+ ):
if shared.script_is_unloading:
- return weechat.WEECHAT_RC_OK
+ return
+
if self.buffer_pointer in shared.buffers:
del shared.buffers[self.buffer_pointer]
+
+ if call_buffer_close and self.buffer_pointer is not None:
+ weechat.buffer_close(self.buffer_pointer)
+
self.buffer_pointer = None
self.last_printed_ts = None
self.hotlist_tss.clear()
- return weechat.WEECHAT_RC_OK
diff --git a/slack/slack_conversation.py b/slack/slack_conversation.py
index 6b27940..a87cb3f 100644
--- a/slack/slack_conversation.py
+++ b/slack/slack_conversation.py
@@ -726,18 +726,20 @@ class SlackConversation(SlackBuffer):
if last_read_line_ts and last_read_line_ts != self.last_read:
await self._api.conversations_mark(self, last_read_line_ts)
- async def _buffer_closed(self):
+ async def _buffer_close(
+ self, call_buffer_close: bool = False, update_server: bool = False
+ ):
+ await super()._buffer_close(call_buffer_close, update_server)
+
+ if shared.script_is_unloading:
+ return
+
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)
- if shared.script_is_unloading:
- return weechat.WEECHAT_RC_OK
- run_async(self._buffer_closed())
- return weechat.WEECHAT_RC_OK
+ if update_server:
+ if self.type in ["im", "mpim"]:
+ await self._api.conversations_close(self)
_T = TypeVar("_T", bound=SlackConversation)
diff --git a/slack/slack_workspace.py b/slack/slack_workspace.py
index e869de7..45d453b 100644
--- a/slack/slack_workspace.py
+++ b/slack/slack_workspace.py
@@ -550,7 +550,7 @@ class SlackWorkspace:
or data["type"] == "group_left"
):
if channel.buffer_pointer is not None:
- weechat.buffer_close(channel.buffer_pointer)
+ await channel.close_buffer()
elif data["type"] == "reaction_added" and data["item"]["type"] == "message":
await channel.reaction_add(
SlackTs(data["item"]["ts"]), data["reaction"], data["user"]