aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2019-01-27 01:56:15 +0100
committerTrygve Aaberge <trygveaa@gmail.com>2019-01-27 18:52:08 +0100
commite66b63bcedc7ba31faa6228a75ec4b6d8ce70265 (patch)
treefc9659dc607e35c25a333f6bcc1b618e2035c98f
parent617704145f787911fcce8b19ab71be317cd585fa (diff)
downloadwee-slack-e66b63bcedc7ba31faa6228a75ec4b6d8ce70265.tar.gz
Delete buffer from our own list before closing it
When we close a buffer, weechat invokes a callback so we can unregister the channel. However, when we close the buffer ourselves in the unregister function it caused the unregister function to be called again. By deleting the buffer from our list first, the second invokation of unregister won't find the channel, so the rest isn't run again. This prevents an error from weechat when we sent None into buffer_clear because the channel_buffer had already been set to None. Also does some cleanup. Use global EVENTROUTER, check if channel exists instead of catching exception and remove some unnecessary checks.
-rw-r--r--wee_slack.py35
1 files changed, 13 insertions, 22 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 034d20c..065dc41 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -601,16 +601,12 @@ class WeechatController(object):
complete
Adds a weechat buffer to the list of handled buffers for this EventRouter
"""
- if isinstance(buffer_ptr, basestring):
- try:
- self.buffers[buffer_ptr].destroy_buffer(update_remote)
- if close_buffer:
- w.buffer_close(buffer_ptr)
- del self.buffers[buffer_ptr]
- except:
- dbg("Tried to close unknown buffer")
- else:
- raise InvalidType(type(buffer_ptr))
+ channel = self.buffers.get(buffer_ptr)
+ if channel:
+ channel.destroy_buffer(update_remote)
+ del self.buffers[buffer_ptr]
+ if close_buffer:
+ w.buffer_close(buffer_ptr)
def get_channel_from_buffer_ptr(self, buffer_ptr):
return self.buffers.get(buffer_ptr, None)
@@ -684,13 +680,9 @@ def reconnect_callback(*args):
@utf8_decode
def buffer_closing_callback(signal, sig_type, data):
"""
- complete
Receives a callback from weechat when a buffer is being closed.
- We pass the eventrouter variable name in as a string, as
- that is the only way we can do dependency injection via weechat
- callback, hence the eval.
"""
- eval(signal).weechat_controller.unregister_buffer(data, True, False)
+ EVENTROUTER.weechat_controller.unregister_buffer(data, True, False)
return w.WEECHAT_RC_OK
@@ -1111,6 +1103,9 @@ class SlackTeam(object):
if w.config_string(w.config_get('irc.look.server_buffer')) == 'merge_with_core':
w.buffer_merge(self.channel_buffer, w.buffer_search_main())
+ def destroy_buffer(self, update_remote):
+ pass
+
def set_muted_channels(self, muted_str):
self.muted_channels = {x for x in muted_str.split(',') if x}
for channel in self.channels.itervalues():
@@ -1548,9 +1543,7 @@ class SlackChannel(SlackChannelCommon):
def destroy_buffer(self, update_remote):
self.clear_messages()
- if self.channel_buffer is not None:
- self.channel_buffer = None
- # if update_remote and not eventrouter.shutting_down:
+ self.channel_buffer = None
self.active = False
if update_remote and not self.eventrouter.shutting_down:
s = SlackRequest(self.team.token, SLACK_API_TRANSLATOR[self.type]["leave"], {"channel": self.identifier}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
@@ -2096,10 +2089,8 @@ class SlackThreadChannel(SlackChannelCommon):
# w.buffer_set(self.channel_buffer, "hotlist", "1")
def destroy_buffer(self, update_remote):
- if self.channel_buffer is not None:
- self.channel_buffer = None
+ self.channel_buffer = None
self.got_history = False
- # if update_remote and not eventrouter.shutting_down:
self.active = False
def render(self, message, force=False):
@@ -3929,7 +3920,7 @@ def setup_hooks():
w.hook_timer(3000, 0, 0, "reconnect_callback", "EVENTROUTER")
w.hook_timer(1000 * 60 * 5, 0, 0, "slack_never_away_cb", "")
- w.hook_signal('buffer_closing', "buffer_closing_callback", "EVENTROUTER")
+ w.hook_signal('buffer_closing', "buffer_closing_callback", "")
w.hook_signal('buffer_switch', "buffer_switch_callback", "EVENTROUTER")
w.hook_signal('window_switch', "buffer_switch_callback", "EVENTROUTER")
w.hook_signal('quit', "quit_notification_callback", "")