Use Quotient's Add3PIDJob
This commit is contained in:
@@ -172,8 +172,6 @@ add_library(neochat STATIC
|
|||||||
models/threepidmodel.h
|
models/threepidmodel.h
|
||||||
threepidaddhelper.cpp
|
threepidaddhelper.cpp
|
||||||
threepidaddhelper.h
|
threepidaddhelper.h
|
||||||
jobs/neochatadd3pidjob.cpp
|
|
||||||
jobs/neochatadd3pidjob.h
|
|
||||||
identityserverhelper.cpp
|
identityserverhelper.cpp
|
||||||
identityserverhelper.h
|
identityserverhelper.h
|
||||||
enums/powerlevel.cpp
|
enums/powerlevel.cpp
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com>
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
||||||
|
|
||||||
#include "neochatadd3pidjob.h"
|
|
||||||
|
|
||||||
using namespace Quotient;
|
|
||||||
|
|
||||||
NeochatAdd3PIdJob::NeochatAdd3PIdJob(const QString &clientSecret, const QString &sid, const std::optional<QJsonObject> &auth)
|
|
||||||
: BaseJob(HttpVerb::Post, u"Add3PIDJob"_s, makePath("/_matrix/client/v3", "/account/3pid/add"))
|
|
||||||
{
|
|
||||||
QJsonObject _dataJson;
|
|
||||||
addParam<IfNotEmpty>(_dataJson, u"auth"_s, auth);
|
|
||||||
addParam<>(_dataJson, u"client_secret"_s, clientSecret);
|
|
||||||
addParam<>(_dataJson, u"sid"_s, sid);
|
|
||||||
setRequestData({_dataJson});
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com>
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <Quotient/jobs/basejob.h>
|
|
||||||
|
|
||||||
class NeochatAdd3PIdJob : public Quotient::BaseJob
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit NeochatAdd3PIdJob(const QString &clientSecret, const QString &sid, const std::optional<QJsonObject> &auth = {});
|
|
||||||
};
|
|
||||||
@@ -4,13 +4,14 @@
|
|||||||
#include "threepidaddhelper.h"
|
#include "threepidaddhelper.h"
|
||||||
|
|
||||||
#include <Quotient/converters.h>
|
#include <Quotient/converters.h>
|
||||||
|
#include <Quotient/csapi/administrative_contact.h>
|
||||||
#include <Quotient/csapi/definitions/auth_data.h>
|
#include <Quotient/csapi/definitions/auth_data.h>
|
||||||
#include <Quotient/csapi/definitions/request_msisdn_validation.h>
|
#include <Quotient/csapi/definitions/request_msisdn_validation.h>
|
||||||
|
|
||||||
#include "jobs/neochatadd3pidjob.h"
|
|
||||||
#include "neochatconnection.h"
|
#include "neochatconnection.h"
|
||||||
|
|
||||||
using namespace Qt::StringLiterals;
|
using namespace Qt::StringLiterals;
|
||||||
|
using namespace Quotient;
|
||||||
|
|
||||||
ThreePIdAddHelper::ThreePIdAddHelper(QObject *parent)
|
ThreePIdAddHelper::ThreePIdAddHelper(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
@@ -139,20 +140,19 @@ ThreePIdAddHelper::ThreePIdStatus ThreePIdAddHelper::newIdStatus() const
|
|||||||
|
|
||||||
void ThreePIdAddHelper::finalizeNewIdAdd(const QString &password)
|
void ThreePIdAddHelper::finalizeNewIdAdd(const QString &password)
|
||||||
{
|
{
|
||||||
const auto job = m_connection->callApi<NeochatAdd3PIdJob>(m_newIdSecret, m_newIdSid);
|
const auto job = m_connection->callApi<Add3PIDJob>(m_newIdSecret, m_newIdSid);
|
||||||
connect(job, &Quotient::BaseJob::result, this, [this, job, password] {
|
connect(job, &Quotient::BaseJob::result, this, [this, job, password] {
|
||||||
m_newIdStatus = Authentication;
|
m_newIdStatus = Authentication;
|
||||||
Q_EMIT newIdStatusChanged();
|
Q_EMIT newIdStatusChanged();
|
||||||
|
|
||||||
if (static_cast<Quotient::BaseJob::StatusCode>(job->error()) == Quotient::BaseJob::Unauthorised) {
|
if (static_cast<Quotient::BaseJob::StatusCode>(job->error()) == Quotient::BaseJob::Unauthorised) {
|
||||||
QJsonObject replyData = job->jsonData();
|
QJsonObject replyData = job->jsonData();
|
||||||
QJsonObject authData;
|
AuthenticationData authData;
|
||||||
authData["session"_L1] = replyData["session"_L1];
|
authData.session = replyData["session"_L1].toString();
|
||||||
authData["password"_L1] = password;
|
authData.authInfo["password"_L1] = password;
|
||||||
authData["type"_L1] = "m.login.password"_L1;
|
authData.type = "m.login.password"_L1;
|
||||||
QJsonObject identifier = {{"type"_L1, "m.id.user"_L1}, {"user"_L1, m_connection->userId()}};
|
authData.authInfo["identifier"_L1] = QJsonObject{{"type"_L1, "m.id.user"_L1}, {"user"_L1, m_connection->userId()}};
|
||||||
authData["identifier"_L1] = identifier;
|
const auto innerJob = m_connection->callApi<Add3PIDJob>(m_newIdSecret, m_newIdSid, authData);
|
||||||
const auto innerJob = m_connection->callApi<NeochatAdd3PIdJob>(m_newIdSecret, m_newIdSid, authData);
|
|
||||||
connect(innerJob, &Quotient::BaseJob::success, this, [this]() {
|
connect(innerJob, &Quotient::BaseJob::success, this, [this]() {
|
||||||
m_connection->threePIdModel()->refreshModel();
|
m_connection->threePIdModel()->refreshModel();
|
||||||
m_newIdSecret.clear();
|
m_newIdSecret.clear();
|
||||||
|
|||||||
Reference in New Issue
Block a user