aboutsummaryrefslogtreecommitdiff
path: root/lib/connection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/connection.cpp')
-rw-r--r--lib/connection.cpp75
1 files changed, 39 insertions, 36 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 8c87d775..cc140ae4 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -175,52 +175,55 @@ void Connection::resolveServer(const QString& mxidOrDomain)
maybeBaseUrl.setScheme("https"); // Instead of the Qt-default "http"
if (!match.hasMatch() || !maybeBaseUrl.isValid())
{
- emit resolveError(
- tr("%1 is not a valid homeserver address")
- .arg(maybeBaseUrl.toString()));
+ emit resolveError(tr("%1 is not a valid homeserver address")
+ .arg(maybeBaseUrl.toString()));
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, [this, getWellKnownJob, maybeBaseUrl] {
- if (getWellKnownJob->status() == BaseJob::NotFoundError) {
- qCDebug(MAIN) << "No .well-known file, IGNORE";
- } else if (getWellKnownJob->status() != BaseJob::Success) {
- qCDebug(MAIN) << "Fetching .well-known file failed, FAIL_PROMPT";
- emit resolveError(tr("Fetching .well-known file failed"));
- return;
- } else if (getWellKnownJob->data().homeserver.baseUrl.isEmpty()) {
- qCDebug(MAIN) << "base_url not provided, FAIL_PROMPT";
- emit resolveError(tr("base_url not provided"));
- return;
- } else if (!QUrl(getWellKnownJob->data().homeserver.baseUrl).isValid()) {
- qCDebug(MAIN) << "base_url invalid, FAIL_ERROR";
- emit resolveError(tr("base_url invalid"));
- return;
- } else {
- QUrl baseUrl(getWellKnownJob->data().homeserver.baseUrl);
-
- qCDebug(MAIN) << ".well-known for" << maybeBaseUrl.host() << "is" << baseUrl.authority();
- setHomeserver(baseUrl);
- }
-
- auto getVersionsJob = callApi<GetVersionsJob>();
-
- connect(getVersionsJob, &BaseJob::finished, [this, getVersionsJob] {
- if (getVersionsJob->status() == BaseJob::Success) {
- qCDebug(MAIN) << "homeserver url is valid";
- emit resolved();
+ connect(getWellKnownJob, &BaseJob::finished, this,
+ [this, getWellKnownJob, maybeBaseUrl] {
+ if (getWellKnownJob->status() != BaseJob::NotFoundError) {
+ if (getWellKnownJob->status() != BaseJob::Success) {
+ qCWarning(MAIN)
+ << "Fetching .well-known file failed, FAIL_PROMPT";
+ emit resolveError(tr("Failed resolving the homeserver"));
+ return;
+ }
+ QUrl baseUrl { getWellKnownJob->data().homeserver.baseUrl };
+ if (baseUrl.isEmpty()) {
+ qCWarning(MAIN) << "base_url not provided, FAIL_PROMPT";
+ emit resolveError(
+ tr("The homeserver base URL is not provided"));
+ return;
+ }
+ if (!baseUrl.isValid()) {
+ qCWarning(MAIN) << "base_url invalid, FAIL_ERROR";
+ emit resolveError(tr("The homeserver base URL is invalid"));
+ return;
+ }
+ qCInfo(MAIN) << ".well-known URL for" << maybeBaseUrl.host()
+ << "is" << baseUrl.authority();
+ setHomeserver(baseUrl);
} else {
- qCDebug(MAIN) << "homeserver url invalid";
- emit resolveError(tr("homeserver url invalid"));
+ qCInfo(MAIN) << "No .well-known file, using" << maybeBaseUrl
+ << "for base URL";
+ setHomeserver(maybeBaseUrl);
}
+
+ auto getVersionsJob = callApi<GetVersionsJob>();
+ 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"));
+ });
});
- });
}
inline UserIdentifier makeUserIdentifier(const QString& id)