mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-24 03:58:49 +03:00
Require matrix v1.1 or greater
This commit is contained in:
parent
6e97f3da06
commit
5772447874
7 changed files with 98 additions and 47 deletions
|
@ -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 "")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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,47 +104,64 @@ 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) {
|
||||
if (err) {
|
||||
if (err->status_code == 404) {
|
||||
setHsError(
|
||||
tr("The required endpoints were not found. Possibly not a Matrix server."));
|
||||
emit hsErrorChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!err->parse_error.empty()) {
|
||||
setHsError(
|
||||
tr("Received malformed response. Make sure the homeserver domain is valid."));
|
||||
emit hsErrorChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
setHsError(tr("An unknown error occured. Make sure the homeserver domain is valid."));
|
||||
emit hsErrorChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
http::client()->registration(
|
||||
[this](const mtx::responses::Register &, mtx::http::RequestErr e) {
|
||||
nhlog::net()->debug("Registration check: {}", e);
|
||||
|
||||
if (!e) {
|
||||
setHsError(tr("Server does not support querying registration flows!"));
|
||||
emit hsErrorChanged();
|
||||
return;
|
||||
}
|
||||
if (e->status_code != 401) {
|
||||
setHsError(tr("Server does not support registration."));
|
||||
http::client()->versions(
|
||||
[this](const mtx::responses::Versions &versions, mtx::http::RequestErr err) {
|
||||
if (err) {
|
||||
if (err->status_code == 404) {
|
||||
setHsError(
|
||||
tr("The required endpoints were not found. Possibly not a Matrix server."));
|
||||
emit hsErrorChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
supported_ = true;
|
||||
lookingUpHs_ = false;
|
||||
emit lookingUpHsChanged();
|
||||
});
|
||||
});
|
||||
if (!err->parse_error.empty()) {
|
||||
setHsError(
|
||||
tr("Received malformed response. Make sure the homeserver domain is valid."));
|
||||
emit hsErrorChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
setHsError(tr("An unknown error occured. Make sure the homeserver domain is valid."));
|
||||
emit hsErrorChanged();
|
||||
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);
|
||||
|
||||
if (!e) {
|
||||
setHsError(tr("Server does not support querying registration flows!"));
|
||||
emit hsErrorChanged();
|
||||
return;
|
||||
}
|
||||
if (e->status_code != 401) {
|
||||
setHsError(tr("Server does not support registration."));
|
||||
emit hsErrorChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
supported_ = true;
|
||||
lookingUpHs_ = false;
|
||||
emit lookingUpHsChanged();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue