Merge pull request #77 from deepbluev7/0.7.0-dev
Add .well-known support
fixes #9
3 files changed, 42 insertions, 6 deletions
diff --git a/src/LoginPage.cpp b/src/LoginPage.cpp
index f702832f..0e7a18d4 100644
--- a/src/LoginPage.cpp
+++ b/src/LoginPage.cpp
@@ -20,6 +20,7 @@
#include <mtx/identifiers.hpp>
#include "Config.h"
+#include "Logging.h"
#include "LoginPage.h"
#include "MatrixClient.h"
#include "ui/FlatButton.h"
@@ -186,7 +187,37 @@ LoginPage::onMatrixIdEntered()
serverInput_->setText(homeServer);
http::client()->set_server(user.hostname());
- checkHomeserverVersion();
+ http::client()->well_known([this](const mtx::responses::WellKnown &res,
+ mtx::http::RequestErr err) {
+ if (err) {
+ using namespace boost::beast::http;
+
+ if (err->status_code == status::not_found) {
+ nhlog::net()->info("Autodiscovery: No .well-known.");
+ checkHomeserverVersion();
+ return;
+ }
+
+ if (!err->parse_error.empty()) {
+ emit versionErrorCb(
+ tr("Autodiscovery failed. Received malformed response."));
+ nhlog::net()->error(
+ "Autodiscovery failed. Received malformed response.");
+ return;
+ }
+
+ emit versionErrorCb(tr("Autodiscovery failed. Unknown error when "
+ "requesting .well-known."));
+ nhlog::net()->error("Autodiscovery failed. Unknown error when "
+ "requesting .well-known.");
+ return;
+ }
+
+ nhlog::net()->info("Autodiscovery: Discovered '" + res.homeserver.base_url +
+ "'");
+ http::client()->set_server(res.homeserver.base_url);
+ checkHomeserverVersion();
+ });
}
}
@@ -272,7 +303,6 @@ LoginPage::onLoginButtonClicked()
if (password_input_->text().isEmpty())
return loginError(tr("Empty password"));
- http::client()->set_server(serverInput_->text().toStdString());
http::client()->login(
user.localpart(),
password_input_->text().toStdString(),
@@ -285,6 +315,12 @@ LoginPage::onLoginButtonClicked()
return;
}
+ if (res.well_known) {
+ http::client()->set_server(res.well_known->homeserver.base_url);
+ nhlog::net()->info("Login requested to user server: " +
+ res.well_known->homeserver.base_url);
+ }
+
emit loginOk(res);
});
diff --git a/src/Utils.cpp b/src/Utils.cpp
index 690a9a9a..3d304e7d 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -342,10 +342,10 @@ utils::linkColor()
return QPalette().color(QPalette::Link).name();
}
-int
+uint32_t
utils::hashQString(const QString &input)
{
- auto hash = 0;
+ uint32_t hash = 0;
for (int i = 0; i < input.length(); i++) {
hash = input.at(i).digitValue() + ((hash << 5) - hash);
@@ -363,7 +363,7 @@ utils::generateContrastingHexColor(const QString &input, const QString &backgrou
// Create a color for the input
auto hash = hashQString(input);
// create a hue value based on the hash of the input.
- auto userHue = qAbs(hash % 360);
+ auto userHue = static_cast<int>(qAbs(hash % 360));
// start with moderate saturation and lightness values.
auto sat = 220;
auto lightness = 125;
diff --git a/src/Utils.h b/src/Utils.h
index bf941c4c..0f022770 100644
--- a/src/Utils.h
+++ b/src/Utils.h
@@ -243,7 +243,7 @@ QString
linkColor();
//! Returns the hash code of the input QString
-int
+uint32_t
hashQString(const QString &input);
//! Generate a color (matching #RRGGBB) that has an acceptable contrast to background that is based
|