From 158f73f70c7eb24f1e66ec8ddc5c1260aa48d69e Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Wed, 5 Nov 2014 01:31:33 +0100 Subject: Do not enable xep_0199 in the ping plugin, it's always enabled anyway --- plugins/ping.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/ping.py b/plugins/ping.py index 4ec706b3..a28406d1 100644 --- a/plugins/ping.py +++ b/plugins/ping.py @@ -31,8 +31,6 @@ import time class Plugin(BasePlugin): def init(self): - self.core.xmpp.register_plugin('xep_0199') - self.core.xmpp.plugin['xep_0115'].update_caps() self.api.add_command('ping', self.command_ping, usage='', help='Send an XMPP ping to jid (see XEP-0199).', -- cgit v1.2.3 From 81ae3e7eeca844f27e70f7064da400bf404d4a0e Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Wed, 5 Nov 2014 03:06:46 +0100 Subject: Implement MUC self-ping to regularly check if we are still in the room --- src/tabs/muctab.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/tabs/muctab.py b/src/tabs/muctab.py index 547830cb..8ac9b7e2 100644 --- a/src/tabs/muctab.py +++ b/src/tabs/muctab.py @@ -67,6 +67,8 @@ class MucTab(ChatTab): self.topic = '' self.topic_from = '' self.remote_wants_chatstates = True + # Self ping event, so we can cancel it when we leave the room + self.self_ping_event = None # We send active, composing and paused states to the MUC because # the chatstate may or may not be filtered by the MUC, # that’s not our problem. @@ -1049,6 +1051,9 @@ class MucTab(ChatTab): self.core.current_tab().input.refresh() self.core.doupdate() self.core.enable_private_tabs(self.name) + # Enable the self ping event, to regularly check if we + # are still in the room. + self.enable_self_ping_event() else: change_nick = '303' in status_codes kick = '307' in status_codes and typ == 'unavailable' @@ -1439,6 +1444,9 @@ class MucTab(ChatTab): if self is not self.core.current_tab(): self.state = 'disconnected' self.joined = False + if self.self_ping_event is not None: + self.core.remove_timed_event(self.self_ping_event) + self.self_ping_event = None def get_single_line_topic(self): """ @@ -1552,4 +1560,27 @@ class MucTab(ChatTab): def matching_names(self): return [(1, safeJID(self.name).user), (3, self.name)] + def enable_self_ping_event(self): + delay = config.get_by_tabname("self_ping_delay", self.general_jid, default=60) + if delay <= 0: # use 0 or some negative value to disable it + return + self.self_ping_event = timed_events.DelayedEvent(delay, self.send_self_ping) + self.core.add_timed_event(self.self_ping_event) + + def send_self_ping(self): + to = self.name + "/" + self.own_nick + self.core.xmpp.plugin['xep_0199'].send_ping(jid=to, + callback=self.on_self_ping_result, + timeout_callback=self.on_self_ping_failed, + timeout=10) + + def on_self_ping_result(self, iq): + if iq["type"] == "error": + self.command_part(iq["error"]["text"] or "not in this room") + self.core.refresh_window() + else: # Re-send a self-ping in a few seconds + self.enable_self_ping_event() + def on_self_ping_failed(self, iq): + self.command_part("the MUC server is not responding") + self.core.refresh_window() -- cgit v1.2.3 From 1faf8576e22948e51c8493f05d6f576588ad847a Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Wed, 5 Nov 2014 03:07:31 +0100 Subject: Remove DelayedEvent.repetive (sic) member which is not used --- src/timed_events.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/timed_events.py b/src/timed_events.py index 6160645b..7f43d05f 100644 --- a/src/timed_events.py +++ b/src/timed_events.py @@ -35,7 +35,6 @@ class DelayedEvent(object): """ self.callback = callback self.args = args - self.repetive = False self.delay = delay # An asyncio handler, as returned by call_later() or call_at() self.handler = None -- cgit v1.2.3