From d82194af58c8ff92634ce57ef293894ec4422efa Mon Sep 17 00:00:00 2001 From: fiaxh Date: Mon, 30 Oct 2017 01:43:26 +0100 Subject: Go offline before quiting application fixes #141 --- libdino/src/application.vala | 3 +++ libdino/src/service/connection_manager.vala | 25 ++++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) (limited to 'libdino/src') diff --git a/libdino/src/application.vala b/libdino/src/application.vala index c9283127..ff0827f8 100644 --- a/libdino/src/application.vala +++ b/libdino/src/application.vala @@ -42,6 +42,9 @@ public interface Dino.Application : GLib.Application { stream_interactor.connection_manager.log_options = print_xmpp; restore(); }); + shutdown.connect(() => { + stream_interactor.connection_manager.make_offline_all(); + }); open.connect((files, hint) => { if (files.length != 1) { warning("Can't handle more than one URI at once."); diff --git a/libdino/src/service/connection_manager.vala b/libdino/src/service/connection_manager.vala index 60cd335a..4c72f229 100644 --- a/libdino/src/service/connection_manager.vala +++ b/libdino/src/service/connection_manager.vala @@ -130,14 +130,29 @@ public class ConnectionManager { return null; } - public void disconnect(Account account) { + public void make_offline_all() { + foreach (Account account in connection_todo) { + make_offline(account); + } + } + + private void make_offline(Account account) { + Xmpp.Presence.Stanza presence = new Xmpp.Presence.Stanza(); + presence.type_ = Xmpp.Presence.Stanza.TYPE_UNAVAILABLE; change_connection_state(account, ConnectionState.DISCONNECTED); + try { + connections[account].stream.get_module(Presence.Module.IDENTITY).send_presence(connections[account].stream, presence); + } catch (Error e) { print(@"on_prepare_for_sleep error $(e.message)\n"); } + } + + public void disconnect(Account account) { + make_offline(account); + try { + connections[account].stream.disconnect(); + } catch (Error e) { print(@"on_prepare_for_sleep error $(e.message)\n"); } connection_todo.remove(account); if (connections.has_key(account)) { - try { - connections[account].stream.disconnect(); - connections.unset(account); - } catch (Error e) { } + connections.unset(account); } } -- cgit v1.2.3-70-g09d2