summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2014-11-05 03:06:46 +0100
committerFlorent Le Coz <louiz@louiz.org>2014-11-05 03:06:46 +0100
commitb6cb6a3fdf240e7c3c7d925e674d8cf5d7729cb4 (patch)
treec257e8d3ce95ee65c3e6ef34e3cbcf32d18870b1 /src
parent9db5f12d047791678afa396fa743d052dc9d1a6c (diff)
downloadpoezio-b6cb6a3fdf240e7c3c7d925e674d8cf5d7729cb4.tar.gz
poezio-b6cb6a3fdf240e7c3c7d925e674d8cf5d7729cb4.tar.bz2
poezio-b6cb6a3fdf240e7c3c7d925e674d8cf5d7729cb4.tar.xz
poezio-b6cb6a3fdf240e7c3c7d925e674d8cf5d7729cb4.zip
Implement MUC self-ping to regularly check if we are still in the room
Diffstat (limited to 'src')
-rw-r--r--src/tabs/muctab.py31
1 files changed, 31 insertions, 0 deletions
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()