From 8f82ce6ffb66f6f96bff936ae7d2f7f1e97baf23 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Wed, 25 Dec 2024 16:19:56 +0100 Subject: [PATCH] Use Quotient's Add3PIDJob --- src/CMakeLists.txt | 2 -- src/jobs/neochatadd3pidjob.cpp | 16 ---------------- src/jobs/neochatadd3pidjob.h | 12 ------------ src/threepidaddhelper.cpp | 18 +++++++++--------- 4 files changed, 9 insertions(+), 39 deletions(-) delete mode 100644 src/jobs/neochatadd3pidjob.cpp delete mode 100644 src/jobs/neochatadd3pidjob.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4ba57ba42..53b2d7acf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/jobs/neochatadd3pidjob.cpp b/src/jobs/neochatadd3pidjob.cpp deleted file mode 100644 index 321dac7bd..000000000 --- a/src/jobs/neochatadd3pidjob.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// SPDX-FileCopyrightText: 2024 James Graham -// 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 &auth) - : BaseJob(HttpVerb::Post, u"Add3PIDJob"_s, makePath("/_matrix/client/v3", "/account/3pid/add")) -{ - QJsonObject _dataJson; - addParam(_dataJson, u"auth"_s, auth); - addParam<>(_dataJson, u"client_secret"_s, clientSecret); - addParam<>(_dataJson, u"sid"_s, sid); - setRequestData({_dataJson}); -} diff --git a/src/jobs/neochatadd3pidjob.h b/src/jobs/neochatadd3pidjob.h deleted file mode 100644 index 2bf3e5b59..000000000 --- a/src/jobs/neochatadd3pidjob.h +++ /dev/null @@ -1,12 +0,0 @@ -// SPDX-FileCopyrightText: 2024 James Graham -// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL - -#pragma once - -#include - -class NeochatAdd3PIdJob : public Quotient::BaseJob -{ -public: - explicit NeochatAdd3PIdJob(const QString &clientSecret, const QString &sid, const std::optional &auth = {}); -}; diff --git a/src/threepidaddhelper.cpp b/src/threepidaddhelper.cpp index 27a0e8826..5a5f91ad3 100644 --- a/src/threepidaddhelper.cpp +++ b/src/threepidaddhelper.cpp @@ -4,13 +4,14 @@ #include "threepidaddhelper.h" #include +#include #include #include -#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(m_newIdSecret, m_newIdSid); + const auto job = m_connection->callApi(m_newIdSecret, m_newIdSid); connect(job, &Quotient::BaseJob::result, this, [this, job, password] { m_newIdStatus = Authentication; Q_EMIT newIdStatusChanged(); if (static_cast(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(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(m_newIdSecret, m_newIdSid, authData); connect(innerJob, &Quotient::BaseJob::success, this, [this]() { m_connection->threePIdModel()->refreshModel(); m_newIdSecret.clear();