aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2020-03-30 19:16:11 +0200
committerKitsune Ral <Kitsune-Ral@users.sf.net>2020-03-30 20:01:19 +0200
commit0a7008bfd345afb083d8ac8c0c6cf21f879aedc6 (patch)
tree75b4140d1ca006046c8a17116598e5e1f138b4b5
parentd38516e4e123474876e4fc7f850fe321ec5ccb54 (diff)
downloadlibquotient-0a7008bfd345afb083d8ac8c0c6cf21f879aedc6.tar.gz
libquotient-0a7008bfd345afb083d8ac8c0c6cf21f879aedc6.zip
Connection::resolveServer(): refactor
Also: use 4-arg connect() to make sure lambdas are disconnected if the connection is gone.
-rw-r--r--lib/connection.cpp49
1 files changed, 23 insertions, 26 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 021ff5dd..6babcf27 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -253,51 +253,48 @@ void Connection::resolveServer(const QString& mxid)
return;
}
- setHomeserver(maybeBaseUrl);
-
auto domain = maybeBaseUrl.host();
qCDebug(MAIN) << "Finding the server" << domain;
+ d->data->setBaseUrl(maybeBaseUrl); // Just enough to check .well-known file
auto getWellKnownJob = callApi<GetWellknownJob>();
- connect(
- getWellKnownJob, &BaseJob::finished,
+ connect(getWellKnownJob, &BaseJob::finished, this,
[this, getWellKnownJob, maybeBaseUrl] {
- if (getWellKnownJob->status() == BaseJob::NotFoundError)
- qCDebug(MAIN) << "No .well-known file, IGNORE";
- else {
+ if (getWellKnownJob->status() != BaseJob::NotFoundError) {
if (getWellKnownJob->status() != BaseJob::Success) {
- qCDebug(MAIN)
+ qCWarning(MAIN)
<< "Fetching .well-known file failed, FAIL_PROMPT";
- emit resolveError(tr("Fetching .well-known file failed"));
+ emit resolveError(tr("Failed resolving the homeserver"));
return;
}
- QUrl baseUrl(getWellKnownJob->data().homeserver.baseUrl);
+ QUrl baseUrl { getWellKnownJob->data().homeserver.baseUrl };
if (baseUrl.isEmpty()) {
- qCDebug(MAIN) << "base_url not provided, FAIL_PROMPT";
- emit resolveError(tr("base_url not provided"));
+ qCWarning(MAIN) << "base_url not provided, FAIL_PROMPT";
+ emit resolveError(
+ tr("The homeserver base URL is not provided"));
return;
}
if (!baseUrl.isValid()) {
- qCDebug(MAIN) << "base_url invalid, FAIL_ERROR";
- emit resolveError(tr("base_url invalid"));
+ qCWarning(MAIN) << "base_url invalid, FAIL_ERROR";
+ emit resolveError(tr("The homeserver base URL is invalid"));
return;
}
-
- qCDebug(MAIN) << ".well-known for" << maybeBaseUrl.host()
- << "is" << baseUrl.toString();
+ qCInfo(MAIN) << ".well-known URL for" << maybeBaseUrl.host()
+ << "is" << baseUrl.authority();
setHomeserver(baseUrl);
+ } else {
+ qCInfo(MAIN) << "No .well-known file, using" << maybeBaseUrl
+ << "for base URL";
+ setHomeserver(maybeBaseUrl);
}
auto getVersionsJob = callApi<GetVersionsJob>();
-
- connect(getVersionsJob, &BaseJob::finished, [this, getVersionsJob] {
- if (getVersionsJob->status() == BaseJob::Success) {
- qCDebug(MAIN) << "homeserver url is valid";
- emit resolved();
- } else {
- qCDebug(MAIN) << "homeserver url invalid";
- emit resolveError(tr("homeserver url invalid"));
- }
+ connect(getVersionsJob, &BaseJob::success, this,
+ &Connection::resolved);
+ connect(getVersionsJob, &BaseJob::failure, this, [this] {
+ qCWarning(MAIN) << "Homeserver base URL invalid";
+ emit resolveError(tr("The homeserver base URL "
+ "doesn't seem to work"));
});
});
}