Require matrix v1.1 or greater

This commit is contained in:
Nicolas Werner 2022-06-25 16:16:54 +02:00
parent 6e97f3da06
commit 5772447874
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
7 changed files with 98 additions and 47 deletions

View file

@ -579,7 +579,7 @@ if(USE_BUNDLED_MTXCLIENT)
FetchContent_Declare(
MatrixClient
GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git
GIT_TAG 9ef7f7503c88b2a27e551324bd39a556b56aa8d6
GIT_TAG e93779692fcc00de136234dd48d0af354717b0a1
)
set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "")
set(BUILD_LIB_TESTS OFF CACHE INTERNAL "")

View file

@ -203,7 +203,7 @@ modules:
buildsystem: cmake-ninja
name: mtxclient
sources:
- commit: 9ef7f7503c88b2a27e551324bd39a556b56aa8d6
- commit: e93779692fcc00de136234dd48d0af354717b0a1
#tag: v0.7.0
type: git
url: https://github.com/Nheko-Reborn/mtxclient.git

View file

@ -76,10 +76,12 @@ Item {
}
MatrixText {
Layout.fillWidth: true
textFormat: Text.PlainText
color: Nheko.theme.error
text: login.mxidError
visible: text
wrapMode: TextEdit.Wrap
}
MatrixTextField {
@ -130,10 +132,12 @@ Item {
}
MatrixText {
Layout.fillWidth: true
textFormat: Text.PlainText
color: Nheko.theme.error
text: loginPage.error
visible: text
wrapMode: TextEdit.Wrap
}
FlatButton {

View file

@ -75,10 +75,12 @@ Item {
}
MatrixText {
Layout.fillWidth: true
textFormat: Text.PlainText
color: Nheko.theme.error
text: regis.hsError
visible: text
wrapMode: TextEdit.Wrap
}
RowLayout {
@ -122,10 +124,12 @@ Item {
}
MatrixText {
Layout.fillWidth: true
textFormat: Text.PlainText
color: Nheko.theme.error
text: regis.usernameError
visible: text
visible: text && regis.supported
wrapMode: TextEdit.Wrap
}
@ -147,10 +151,12 @@ Item {
}
MatrixText {
Layout.fillWidth: true
visible: regis.supported
textFormat: Text.PlainText
color: Nheko.theme.error
text: passwordLabel.text != passwordConfirmationLabel.text ? qsTr("Your passwords do not match!") : ""
wrapMode: TextEdit.Wrap
}
MatrixTextField {
@ -177,10 +183,12 @@ Item {
}
MatrixText {
Layout.fillWidth: true
textFormat: Text.PlainText
color: Nheko.theme.error
text: registrationPage.error
visible: text
wrapMode: TextEdit.Wrap
}
FlatButton {

View file

@ -6,9 +6,12 @@
#include <QDesktopServices>
#include <set>
#include <mtx/identifiers.hpp>
#include <mtx/requests.hpp>
#include <mtx/responses/login.hpp>
#include <mtx/responses/version.hpp>
#include "Config.h"
#include "Logging.h"
@ -149,7 +152,8 @@ LoginPage::checkHomeserverVersion()
return;
}
http::client()->versions([this](const mtx::responses::Versions &, mtx::http::RequestErr err) {
http::client()->versions([this](const mtx::responses::Versions &versions,
mtx::http::RequestErr err) {
if (err) {
if (err->status_code == 404) {
emit versionErrorCb(tr("The required endpoints were not found. "
@ -170,6 +174,21 @@ LoginPage::checkHomeserverVersion()
return;
}
if (std::find_if(
versions.versions.cbegin(), versions.versions.cend(), [](const std::string &v) {
static const std::set<std::string_view, std::less<>> supported{
"v1.1",
"v1.2",
"v1.3",
};
return supported.count(v) != 0;
}) == versions.versions.cend()) {
emit versionErrorCb(
tr("The selected server does not support a version of the Matrix protocol, that this "
"client understands (v1.1, v1.2 or v1.3). You can't sign in."));
return;
}
http::client()->get_login([this](mtx::responses::LoginFlows flows,
mtx::http::RequestErr err) {
if (err || flows.flows.empty())

View file

@ -4,8 +4,11 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include <set>
#include <mtx/responses/common.hpp>
#include <mtx/responses/register.hpp>
#include <mtx/responses/version.hpp>
#include <mtx/responses/well-known.hpp>
#include <mtxclient/http/client.hpp>
@ -101,7 +104,8 @@ RegisterPage::versionsCheck()
{
// Make a request to /_matrix/client/versions to check the address
// given is a Matrix homeserver.
http::client()->versions([this](const mtx::responses::Versions &, mtx::http::RequestErr err) {
http::client()->versions(
[this](const mtx::responses::Versions &versions, mtx::http::RequestErr err) {
if (err) {
if (err->status_code == 404) {
setHsError(
@ -122,6 +126,22 @@ RegisterPage::versionsCheck()
return;
}
if (std::find_if(
versions.versions.cbegin(), versions.versions.cend(), [](const std::string &v) {
static const std::set<std::string_view, std::less<>> supported{
"v1.1",
"v1.2",
"v1.3",
};
return supported.count(v) != 0;
}) == versions.versions.cend()) {
emit setHsError(
tr("The selected server does not support a version of the Matrix protocol, that "
"this client understands (v1.1, v1.2 or v1.3). You can't register."));
emit hsErrorChanged();
return;
}
http::client()->registration(
[this](const mtx::responses::Register &, mtx::http::RequestErr e) {
nhlog::net()->debug("Registration check: {}", e);

View file

@ -63,12 +63,12 @@ private:
QString registrationError_, hsError_, usernameError_;
bool registering_;
bool supported_;
bool lookingUpHs_;
bool lookingUpUsername_;
bool usernameAvailable_;
bool usernameUnavailable_;
bool registering_ = false;
bool supported_ = false;
bool lookingUpHs_ = false;
bool lookingUpUsername_ = false;
bool usernameAvailable_ = false;
bool usernameUnavailable_ = false;
QString lastServer;
};