Use Quotient's Add3PIDJob
This commit is contained in:
@@ -172,8 +172,6 @@ add_library(neochat STATIC
|
||||
models/threepidmodel.h
|
||||
threepidaddhelper.cpp
|
||||
threepidaddhelper.h
|
||||
jobs/neochatadd3pidjob.cpp
|
||||
jobs/neochatadd3pidjob.h
|
||||
identityserverhelper.cpp
|
||||
identityserverhelper.h
|
||||
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 <Quotient/converters.h>
|
||||
#include <Quotient/csapi/administrative_contact.h>
|
||||
#include <Quotient/csapi/definitions/auth_data.h>
|
||||
#include <Quotient/csapi/definitions/request_msisdn_validation.h>
|
||||
|
||||
#include "jobs/neochatadd3pidjob.h"
|
||||
#include "neochatconnection.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
using namespace Quotient;
|
||||
|
||||
ThreePIdAddHelper::ThreePIdAddHelper(QObject *parent)
|
||||
: QObject(parent)
|
||||
@@ -139,20 +140,19 @@ ThreePIdAddHelper::ThreePIdStatus ThreePIdAddHelper::newIdStatus() const
|
||||
|
||||
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] {
|
||||
m_newIdStatus = Authentication;
|
||||
Q_EMIT newIdStatusChanged();
|
||||
|
||||
if (static_cast<Quotient::BaseJob::StatusCode>(job->error()) == Quotient::BaseJob::Unauthorised) {
|
||||
QJsonObject replyData = job->jsonData();
|
||||
QJsonObject authData;
|
||||
authData["session"_L1] = replyData["session"_L1];
|
||||
authData["password"_L1] = password;
|
||||
authData["type"_L1] = "m.login.password"_L1;
|
||||
QJsonObject identifier = {{"type"_L1, "m.id.user"_L1}, {"user"_L1, m_connection->userId()}};
|
||||
authData["identifier"_L1] = identifier;
|
||||
const auto innerJob = m_connection->callApi<NeochatAdd3PIdJob>(m_newIdSecret, m_newIdSid, authData);
|
||||
AuthenticationData authData;
|
||||
authData.session = replyData["session"_L1].toString();
|
||||
authData.authInfo["password"_L1] = password;
|
||||
authData.type = "m.login.password"_L1;
|
||||
authData.authInfo["identifier"_L1] = QJsonObject{{"type"_L1, "m.id.user"_L1}, {"user"_L1, m_connection->userId()}};
|
||||
const auto innerJob = m_connection->callApi<Add3PIDJob>(m_newIdSecret, m_newIdSid, authData);
|
||||
connect(innerJob, &Quotient::BaseJob::success, this, [this]() {
|
||||
m_connection->threePIdModel()->refreshModel();
|
||||
m_newIdSecret.clear();
|
||||
|
||||
Reference in New Issue
Block a user