summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--poezio/core/core.py17
-rw-r--r--poezio/core/handlers.py22
2 files changed, 25 insertions, 14 deletions
diff --git a/poezio/core/core.py b/poezio/core/core.py
index 7553c57d..26543add 100644
--- a/poezio/core/core.py
+++ b/poezio/core/core.py
@@ -256,6 +256,9 @@ 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),
+ ('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),
@@ -832,16 +835,12 @@ 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)
- 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:
+ for tab in self.get_tabs(tabs.MucTab):
+ tab.command_part(msg)
+ self.xmpp.disconnect(reason=msg)
def send_message(self, msg: str) -> bool:
"""
diff --git a/poezio/core/handlers.py b/poezio/core/handlers.py
index b79a853b..c17f3761 100644
--- a/poezio/core/handlers.py
+++ b/poezio/core/handlers.py
@@ -1152,20 +1152,32 @@ 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()
+
+ 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
"""
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.", 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