diff options
-rw-r--r-- | libdino/src/service/counterpart_interaction_manager.vala | 2 | ||||
-rw-r--r-- | libdino/src/service/registration.vala | 57 |
2 files changed, 41 insertions, 18 deletions
diff --git a/libdino/src/service/counterpart_interaction_manager.vala b/libdino/src/service/counterpart_interaction_manager.vala index 5ff74eb7..e22ecb53 100644 --- a/libdino/src/service/counterpart_interaction_manager.vala +++ b/libdino/src/service/counterpart_interaction_manager.vala @@ -90,7 +90,7 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object { Entities.Message? message = stream_interactor.get_module(MessageStorage.IDENTITY).get_message_by_stanza_id(stanza_id, conversation); if (message == null) return; // Don't move read marker backwards because we get old info from another client - if (conversation.read_up_to.local_time.compare(message.local_time) > 0) return; + if (conversation.read_up_to == null || conversation.read_up_to.local_time.compare(message.local_time) > 0) return; conversation.read_up_to = message; } else { // We received a marker from someone else. Search the respective message and mark it. diff --git a/libdino/src/service/registration.vala b/libdino/src/service/registration.vala index 19eebb05..073d2b74 100644 --- a/libdino/src/service/registration.vala +++ b/libdino/src/service/registration.vala @@ -23,29 +23,47 @@ public class Register : StreamInteractionModule, Object{ } public async ConnectionManager.ConnectionError.Source? add_check_account(Account account) { - SourceFunc callback = add_check_account.callback; + XmppStream stream = new XmppStream(); + stream.log = new XmppLog(account.bare_jid.to_string(), Application.print_xmpp); + stream.add_module(new Tls.Module()); + stream.add_module(new Iq.Module()); + stream.add_module(new Xep.SrvRecordsTls.Module()); + stream.add_module(new Sasl.Module(account.bare_jid.to_string(), account.password)); + ConnectionManager.ConnectionError.Source? ret = null; - ulong handler_id_connected = stream_interactor.stream_negotiated.connect((connected_account, stream) => { - if (connected_account.equals(account)) { - account.persist(db); - account.enabled = true; - Idle.add((owned)callback); - } + SourceFunc callback = add_check_account.callback; + stream.stream_negotiated.connect(() => { + if (callback == null) return; + Idle.add((owned)callback); }); - ulong handler_id_error = stream_interactor.connection_manager.connection_error.connect((connected_account, error) => { - if (connected_account.equals(account)) { - ret = error.source; - } - stream_interactor.disconnect_account.begin(account); + stream.get_module(Tls.Module.IDENTITY).invalid_certificate.connect((peer_cert, errors) => { + if (callback == null) return; + ret = ConnectionManager.ConnectionError.Source.TLS; + Idle.add((owned)callback); + }); + stream.get_module(Sasl.Module.IDENTITY).received_auth_failure.connect((stream, node) => { + if (callback == null) return; + ret = ConnectionManager.ConnectionError.Source.SASL; Idle.add((owned)callback); }); + stream.connect.begin(account.bare_jid.domainpart, (_, res) => { + try { + stream.connect.end(res); + } catch (Error e) { + debug("Error connecting to stream: %s", e.message); + } + if (callback != null) { + ret = ConnectionManager.ConnectionError.Source.CONNECTION; + Idle.add((owned)callback); + } + }); - stream_interactor.connect_account(account); yield; - stream_interactor.disconnect(handler_id_connected); - stream_interactor.connection_manager.disconnect(handler_id_error); + try { + yield stream.disconnect(); + } catch (Error e) {} return ret; } @@ -164,10 +182,15 @@ public class Register : StreamInteractionModule, Object{ }); yield; + + string? ret = null; if (stream.negotiation_complete) { - return yield stream.get_module(Xep.InBandRegistration.Module.IDENTITY).submit_to_server(stream, jid, form); + ret = yield stream.get_module(Xep.InBandRegistration.Module.IDENTITY).submit_to_server(stream, jid, form); } - return null; + try { + yield stream.disconnect(); + } catch (Error e) {} + return ret; } } |