|
|
@ -109,70 +109,69 @@ RegisterPage::versionsCheck() |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Make a request to /_matrix/client/versions to check the address
|
|
|
|
// Make a request to /_matrix/client/versions to check the address
|
|
|
|
// given is a Matrix homeserver.
|
|
|
|
// given is a Matrix homeserver.
|
|
|
|
http::client()->versions( |
|
|
|
http::client()->versions([this](const mtx::responses::Versions &versions, |
|
|
|
[this](const mtx::responses::Versions &versions, mtx::http::RequestErr err) { |
|
|
|
mtx::http::RequestErr err) { |
|
|
|
if (err) { |
|
|
|
if (err) { |
|
|
|
if (err->status_code == 404) { |
|
|
|
if (err->status_code == 404) { |
|
|
|
setHsError( |
|
|
|
setHsError( |
|
|
|
tr("The required endpoints were not found. Possibly not a Matrix server.")); |
|
|
|
tr("The required endpoints were not found. Possibly not a Matrix server.")); |
|
|
|
emit hsErrorChanged(); |
|
|
|
emit hsErrorChanged(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!err->parse_error.empty()) { |
|
|
|
if (!err->parse_error.empty()) { |
|
|
|
setHsError( |
|
|
|
setHsError( |
|
|
|
tr("Received malformed response. Make sure the homeserver domain is valid.")); |
|
|
|
tr("Received malformed response. Make sure the homeserver domain is valid.")); |
|
|
|
emit hsErrorChanged(); |
|
|
|
emit hsErrorChanged(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setHsError(tr("An unknown error occured. Make sure the homeserver domain is valid.")); |
|
|
|
setHsError(tr("An unknown error occured. Make sure the homeserver domain is valid.")); |
|
|
|
emit hsErrorChanged(); |
|
|
|
emit hsErrorChanged(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (std::find_if( |
|
|
|
if (std::find_if( |
|
|
|
versions.versions.cbegin(), versions.versions.cend(), [](const std::string &v) { |
|
|
|
versions.versions.cbegin(), versions.versions.cend(), [](const std::string &v) { |
|
|
|
static const std::set<std::string_view, std::less<>> supported{ |
|
|
|
static const std::set<std::string_view, std::less<>> supported{ |
|
|
|
"v1.1", |
|
|
|
"v1.1", |
|
|
|
"v1.2", |
|
|
|
"v1.2", |
|
|
|
"v1.3", |
|
|
|
"v1.3", |
|
|
|
"v1.4", |
|
|
|
"v1.4", |
|
|
|
"v1.5", |
|
|
|
"v1.5", |
|
|
|
}; |
|
|
|
}; |
|
|
|
return supported.count(v) != 0; |
|
|
|
return supported.count(v) != 0; |
|
|
|
}) == versions.versions.cend()) { |
|
|
|
}) == versions.versions.cend()) { |
|
|
|
emit setHsError( |
|
|
|
emit setHsError( |
|
|
|
tr("The selected server does not support a version of the Matrix protocol that " |
|
|
|
tr("The selected server does not support a version of the Matrix protocol that " |
|
|
|
"this client understands (v1.1 to v1.5). You can't register.")); |
|
|
|
"this client understands (v1.1 to v1.5). You can't register.")); |
|
|
|
emit hsErrorChanged(); |
|
|
|
emit hsErrorChanged(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
http::client()->registration( |
|
|
|
http::client()->registration([this](const mtx::responses::Register &, |
|
|
|
[this](const mtx::responses::Register &, mtx::http::RequestErr e) { |
|
|
|
mtx::http::RequestErr e) { |
|
|
|
nhlog::net()->debug("Registration check: {}", e); |
|
|
|
nhlog::net()->debug("Registration check: {}", e); |
|
|
|
|
|
|
|
|
|
|
|
if (!e) { |
|
|
|
if (!e) { |
|
|
|
setHsError(tr("Server does not support querying registration flows!")); |
|
|
|
setHsError(tr("Server does not support querying registration flows!")); |
|
|
|
emit hsErrorChanged(); |
|
|
|
emit hsErrorChanged(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (e->status_code != 401) { |
|
|
|
if (e->status_code != 401) { |
|
|
|
setHsError(tr("Server does not support registration.")); |
|
|
|
setHsError(tr("Server does not support registration.")); |
|
|
|
emit hsErrorChanged(); |
|
|
|
emit hsErrorChanged(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (const auto &f : e->matrix_error.unauthorized.flows) |
|
|
|
for (const auto &f : e->matrix_error.unauthorized.flows) |
|
|
|
nhlog::ui()->debug("Registration flows for server: {}", |
|
|
|
nhlog::ui()->debug("Registration flows for server: {}", fmt::join(f.stages, ", ")); |
|
|
|
fmt::join(f.stages, ", ")); |
|
|
|
|
|
|
|
|
|
|
|
supported_ = true; |
|
|
|
supported_ = true; |
|
|
|
lookingUpHs_ = false; |
|
|
|
lookingUpHs_ = false; |
|
|
|
emit lookingUpHsChanged(); |
|
|
|
emit lookingUpHsChanged(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
|