Don't go through ConnectionManager for initial connection attempt
This commit is contained in:
parent
6257e9705c
commit
1eb01251e8
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
SourceFunc callback = add_check_account.callback;
|
||||
stream.stream_negotiated.connect(() => {
|
||||
if (callback == null) return;
|
||||
Idle.add((owned)callback);
|
||||
});
|
||||
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);
|
||||
}
|
||||
});
|
||||
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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue