Compare commits

...

4 commits

Author SHA1 Message Date
Povilas Kanapickas
bb7b57c6d1
Merge fb610a3d07 into 1a00d91316 2024-11-05 00:47:48 +08:00
DeepBlueV7.X
1a00d91316
Merge pull request #1833 from Integral-Tech/refactor-string-conversion
refactor: use fmt lib to avoid back-and-forth conversion
2024-10-30 01:10:07 +00:00
Integral
b7a5d714c6
refactor: use fmt lib to avoid back-and-forth conversion 2024-10-19 16:49:12 +08:00
Povilas Kanapickas
fb610a3d07 Do not prevent login if .well-known response is invalid
The current code results in confusing behavior under the following
circumstances:

 - Homeserver is guessed correctly from the Matrix ID

- The server returns invalid (e.g. HTTP 200 with empty body) response
for .well-known data

The user will be presented with "Autodiscovery failed. Received
malformed response" message even though all details are entered
correctly. Login button will not work. The only workaround is to edit
the home server field a few times so that homeserverChanged() and
checkHomeserverVersion() would be invoked.

This is not optimal, especially because autodiscovery based on
.well-known is optional. The solution is to always invoke
checkHomeserverVersion() even when autodiscovery fails due to any
reason.

checkHomeserverVersion() will check the home server against required
Matrix API endpoints. If this fails, user will be presented with error
messages instructing to check home server URL. Accordingly, allowing to
continue in case of failed autodiscovery does not reduce clarity of
errors presented to the user.
2024-09-24 19:02:55 +03:00
2 changed files with 5 additions and 5 deletions

View file

@ -115,17 +115,16 @@ LoginPage::onMatrixIdEntered()
} }
if (!err->parse_error.empty()) { if (!err->parse_error.empty()) {
emit versionErrorCb(tr("Autodiscovery failed. Received malformed response."));
nhlog::net()->error("Autodiscovery failed. Received malformed response. {}", nhlog::net()->error("Autodiscovery failed. Received malformed response. {}",
err->parse_error); err->parse_error);
checkHomeserverVersion();
return; return;
} }
emit versionErrorCb(tr("Autodiscovery failed. Unknown error when "
"requesting .well-known."));
nhlog::net()->error("Autodiscovery failed. Unknown error when " nhlog::net()->error("Autodiscovery failed. Unknown error when "
"requesting .well-known. {}", "requesting .well-known. {}",
*err); *err);
checkHomeserverVersion();
return; return;
} }

View file

@ -20,6 +20,8 @@
#include <QVideoFrame> #include <QVideoFrame>
#include <QVideoSink> #include <QVideoSink>
#include <fmt/format.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <mtx/responses/common.hpp> #include <mtx/responses/common.hpp>
@ -578,8 +580,7 @@ InputBar::message(const QString &msg, MarkdownOverride useMarkdown, bool rainbow
} }
} }
text.body = text.body = fmt::format("{}\n{}", body.toStdString(), text.body);
QStringLiteral("%1\n%2").arg(body, QString::fromStdString(text.body)).toStdString();
// NOTE(Nico): rich replies always need a formatted_body! // NOTE(Nico): rich replies always need a formatted_body!
text.format = "org.matrix.custom.html"; text.format = "org.matrix.custom.html";