From 910240afb6d2c180d0d6a4207a08d6b5a4c2f64b Mon Sep 17 00:00:00 2001 From: Georg Lukas Date: Tue, 26 Mar 2019 11:31:51 +0100 Subject: [PATCH 1/5] Display disconnect reason, depends on slixmpp!12 --- poezio/core/handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/poezio/core/handlers.py b/poezio/core/handlers.py index 030a43e5..9cb9358e 100644 --- a/poezio/core/handlers.py +++ b/poezio/core/handlers.py @@ -1165,7 +1165,7 @@ class HandlerCore: for tab in self.core.get_tabs(tabs.MucTab): tab.disconnect() msg_typ = 'Error' if not self.core.legitimate_disconnect else 'Info' - self.core.information("Disconnected from server.", msg_typ) + self.core.information("Disconnected from server%s." % (event and ": %s" % event or ""), msg_typ) if self.core.legitimate_disconnect or not config.get( 'auto_reconnect', True): return From 40f292d998650abc1b25b6bbf94b9c4b6174a3a8 Mon Sep 17 00:00:00 2001 From: Georg Lukas Date: Tue, 26 Mar 2019 12:13:01 +0100 Subject: [PATCH 2/5] Use new slixmpp!12 disconnect/reconnect semantics --- poezio/core/core.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/poezio/core/core.py b/poezio/core/core.py index 6bb19d16..ed977b6d 100644 --- a/poezio/core/core.py +++ b/poezio/core/core.py @@ -834,14 +834,10 @@ class Core: self.legitimate_disconnect = True for tab in self.get_tabs(tabs.MucTab): tab.command_part(msg) - self.xmpp.disconnect() if reconnect: - # Add a one-time event to reconnect as soon as we are - # effectively disconnected - self.xmpp.add_event_handler( - 'disconnected', - lambda event: self.xmpp.connect(), - disposable=True) + self.xmpp.reconnect(wait=0.0, reason=msg) + else: + self.xmpp.disconnect(reason=msg) def send_message(self, msg: str) -> bool: """ From 46e3dece5e04fd8854596f32266c43083141526b Mon Sep 17 00:00:00 2001 From: Georg Lukas Date: Tue, 26 Mar 2019 12:28:41 +0100 Subject: [PATCH 3/5] Only /part tabs on disconnect, not on reconnect --- poezio/core/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/poezio/core/core.py b/poezio/core/core.py index ed977b6d..cc838541 100644 --- a/poezio/core/core.py +++ b/poezio/core/core.py @@ -832,11 +832,11 @@ class Core: parts of the client (for example, set the MucTabs as not joined, etc) """ self.legitimate_disconnect = True - for tab in self.get_tabs(tabs.MucTab): - tab.command_part(msg) if reconnect: self.xmpp.reconnect(wait=0.0, reason=msg) else: + for tab in self.get_tabs(tabs.MucTab): + tab.command_part(msg) self.xmpp.disconnect(reason=msg) def send_message(self, msg: str) -> bool: From 90a5b3d352529d396088476d299950baf09cadf7 Mon Sep 17 00:00:00 2001 From: Georg Lukas Date: Tue, 26 Mar 2019 14:29:50 +0100 Subject: [PATCH 4/5] Refactor session_end actions out of on_disconnect --- poezio/core/core.py | 2 ++ poezio/core/handlers.py | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/poezio/core/core.py b/poezio/core/core.py index cc838541..1f02c3d8 100644 --- a/poezio/core/core.py +++ b/poezio/core/core.py @@ -256,6 +256,8 @@ class Core: ('roster_update', self.handler.on_roster_update), ('session_start', self.handler.on_session_start), ('session_start', self.handler.on_session_start_features), + ('session_end', self.handler.on_session_end), + ('sm_failed', self.handler.on_session_end), ('ssl_cert', self.handler.validate_ssl), ('ssl_invalid_chain', self.handler.ssl_invalid_chain), ('stream_error', self.handler.on_stream_error), diff --git a/poezio/core/handlers.py b/poezio/core/handlers.py index 9cb9358e..955f8f58 100644 --- a/poezio/core/handlers.py +++ b/poezio/core/handlers.py @@ -1152,18 +1152,23 @@ class HandlerCore: self.core.information( "Connection to remote server failed: %s" % (error, ), 'Error') + def on_session_end(self, event): + """ + Called when a session is terminated (e.g. due to a manual disconnect or a 0198 resume fail) + """ + roster.connected = 0 + roster.modified() + for tab in self.core.get_tabs(tabs.MucTab): + tab.disconnect() + async def on_disconnected(self, event): """ When we are disconnected from remote server """ if 'disconnect' in config.get('beep_on').split(): curses.beep() - roster.connected = 0 # Stop the ping plugin. It would try to send stanza on regular basis self.core.xmpp.plugin['xep_0199'].disable_keepalive() - roster.modified() - for tab in self.core.get_tabs(tabs.MucTab): - tab.disconnect() msg_typ = 'Error' if not self.core.legitimate_disconnect else 'Info' self.core.information("Disconnected from server%s." % (event and ": %s" % event or ""), msg_typ) if self.core.legitimate_disconnect or not config.get( From dc5144fdb9f359e21e4901b523738ae1b20cbcd6 Mon Sep 17 00:00:00 2001 From: Georg Lukas Date: Tue, 26 Mar 2019 14:30:57 +0100 Subject: [PATCH 5/5] Inform the user and re-instate 0199 pinger on a successful 0198 resume --- poezio/core/core.py | 1 + poezio/core/handlers.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/poezio/core/core.py b/poezio/core/core.py index 1f02c3d8..6f840dc2 100644 --- a/poezio/core/core.py +++ b/poezio/core/core.py @@ -258,6 +258,7 @@ class Core: ('session_start', self.handler.on_session_start_features), ('session_end', self.handler.on_session_end), ('sm_failed', self.handler.on_session_end), + ('session_resumed', self.handler.on_session_resumed), ('ssl_cert', self.handler.validate_ssl), ('ssl_invalid_chain', self.handler.ssl_invalid_chain), ('stream_error', self.handler.on_stream_error), diff --git a/poezio/core/handlers.py b/poezio/core/handlers.py index 955f8f58..614cabe4 100644 --- a/poezio/core/handlers.py +++ b/poezio/core/handlers.py @@ -1161,6 +1161,13 @@ class HandlerCore: for tab in self.core.get_tabs(tabs.MucTab): tab.disconnect() + def on_session_resumed(self, event): + """ + Called when a session is successfully resumed by 0198 + """ + self.core.information("Resumed session as %s" % self.core.xmpp.boundjid.full, 'Info') + self.core.xmpp.plugin['xep_0199'].enable_keepalive() + async def on_disconnected(self, event): """ When we are disconnected from remote server