Replace Quotient::Connection with NeoChatConnection where possible

This commit is contained in:
Tobias Fella
2024-04-23 11:31:30 +02:00
parent 66a60f09e3
commit 1e644587b3
38 changed files with 83 additions and 95 deletions

View File

@@ -19,7 +19,6 @@
#include <signal.h>
#include <Quotient/accountregistry.h>
#include <Quotient/connection.h>
#include <Quotient/csapi/logout.h>
#include <Quotient/csapi/notifications.h>
#include <Quotient/eventstats.h>

View File

@@ -117,7 +117,7 @@ private:
Quotient::AccountRegistry m_accountRegistry;
QStringList m_accountsLoading;
QMap<QString, QPointer<Quotient::Connection>> m_connectionsLoading;
QMap<QString, QPointer<NeoChatConnection>> m_connectionsLoading;
QString m_endpoint;
private Q_SLOTS:

View File

@@ -4,7 +4,6 @@
#include "login.h"
#include <Quotient/accountregistry.h>
#include <Quotient/connection.h>
#include <Quotient/qt_connection_util.h>
#include "controller.h"
@@ -54,7 +53,7 @@ void LoginHelper::init()
m_connection = new NeoChatConnection();
}
m_connection->resolveServer(m_matrixId);
connectSingleShot(m_connection, &Connection::loginFlowsChanged, this, [this]() {
connectSingleShot(m_connection.get(), &Connection::loginFlowsChanged, this, [this]() {
setHomeserverReachable(true);
m_testing = false;
Q_EMIT testingChanged();
@@ -100,7 +99,7 @@ void LoginHelper::init()
Q_EMIT Controller::instance().errorOccured(i18n("Network Error"), std::move(error));
});
connectSingleShot(m_connection, &Connection::syncDone, this, [this]() {
connectSingleShot(m_connection.get(), &Connection::syncDone, this, [this]() {
Q_EMIT loaded();
});
}
@@ -182,7 +181,7 @@ QUrl LoginHelper::ssoUrl() const
void LoginHelper::loginWithSso()
{
m_connection->resolveServer(m_matrixId);
connectSingleShot(m_connection, &Connection::loginFlowsChanged, this, [this]() {
connectSingleShot(m_connection.get(), &Connection::loginFlowsChanged, this, [this]() {
SsoSession *session = m_connection->prepareForSso(m_deviceName);
m_ssoUrl = session->ssoUrl();
Q_EMIT ssoUrlChanged();

View File

@@ -146,7 +146,7 @@ private:
QString m_deviceName;
bool m_supportsSso = false;
bool m_supportsPassword = false;
NeoChatConnection *m_connection = nullptr;
QPointer<NeoChatConnection> m_connection;
QUrl m_ssoUrl;
bool m_testing = false;
bool m_isLoggingIn = false;

View File

@@ -14,8 +14,6 @@
#include "neochatconnection.h"
#include <Quotient/connection.h>
using namespace Quotient;
ThumbnailResponse::ThumbnailResponse(QString id, QSize size, NeoChatConnection *connection)

View File

@@ -35,7 +35,7 @@ private:
QSize requestedSize;
const QString localFile;
Quotient::MediaThumbnailJob *job = nullptr;
NeoChatConnection *m_connection;
QPointer<NeoChatConnection> m_connection;
QImage image;
QString errorStr;
@@ -75,6 +75,6 @@ public:
QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) override;
private:
NeoChatConnection *m_connection = nullptr;
QPointer<NeoChatConnection> m_connection;
MatrixImageProvider() = default;
};

View File

@@ -10,6 +10,8 @@
#include <Quotient/events/eventcontent.h>
#include <qcoro/qcorosignal.h>
#include "neochatconnection.h"
using namespace Quotient;
AccountEmoticonModel::AccountEmoticonModel(QObject *parent)
@@ -77,12 +79,12 @@ QHash<int, QByteArray> AccountEmoticonModel::roleNames() const
};
}
Connection *AccountEmoticonModel::connection() const
NeoChatConnection *AccountEmoticonModel::connection() const
{
return m_connection;
}
void AccountEmoticonModel::setConnection(Connection *connection)
void AccountEmoticonModel::setConnection(NeoChatConnection *connection)
{
if (m_connection) {
disconnect(m_connection, nullptr, this, nullptr);

View File

@@ -12,7 +12,7 @@
#include <QPointer>
#include <QQmlEngine>
#include <Quotient/connection.h>
class NeoChatConnection;
/**
* @class AccountEmoticonModel
@@ -29,7 +29,7 @@ class AccountEmoticonModel : public QAbstractListModel
/**
* @brief The connection to get emoticons from.
*/
Q_PROPERTY(Quotient::Connection *connection READ connection WRITE setConnection NOTIFY connectionChanged)
Q_PROPERTY(NeoChatConnection *connection READ connection WRITE setConnection NOTIFY connectionChanged)
public:
enum Roles {
@@ -63,8 +63,8 @@ public:
*/
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
[[nodiscard]] Quotient::Connection *connection() const;
void setConnection(Quotient::Connection *connection);
[[nodiscard]] NeoChatConnection *connection() const;
void setConnection(NeoChatConnection *connection);
/**
* @brief Deletes the emoticon at the given index.
@@ -96,7 +96,7 @@ Q_SIGNALS:
private:
std::optional<Quotient::ImagePackEventContent> m_images;
QPointer<Quotient::Connection> m_connection;
QPointer<NeoChatConnection> m_connection;
QCoro::Task<void> doSetEmoticonImage(int index, QUrl source);
QCoro::Task<void> doAddEmoticon(QUrl source, QString shortcode, QString description, QString type);

View File

@@ -4,6 +4,7 @@
#include "actionsmodel.h"
#include "chatbarcache.h"
#include "neochatconnection.h"
#include "neochatroom.h"
#include "roommanager.h"
#include <Quotient/events/roommemberevent.h>
@@ -260,7 +261,7 @@ QList<ActionsModel::Action> actions{
return QString();
}
Q_EMIT room->showMessage(NeoChatRoom::Info, i18nc("Knocking room <roomname>.", "Knocking room %1.", text));
auto connection = room->connection();
auto connection = dynamic_cast<NeoChatConnection *>(room->connection());
const auto knownServer = roomName.mid(roomName.indexOf(":"_ls) + 1);
if (parts.length() >= 2) {
RoomManager::instance().knockRoom(connection, roomName, parts[1], QStringList{knownServer});

View File

@@ -110,7 +110,7 @@ Q_SIGNALS:
private:
explicit CustomEmojiModel(QObject *parent = nullptr);
QList<CustomEmoji> m_emojis;
NeoChatConnection *m_connection = nullptr;
QPointer<NeoChatConnection> m_connection;
void fetchEmojis();
};

View File

@@ -5,7 +5,8 @@
#include "customemojimodel.h"
#include <QRegularExpression>
#include <connection.h>
class NeoChatConnection;
struct CustomEmoji {
QString name; // with :semicolons:
@@ -14,6 +15,6 @@ struct CustomEmoji {
};
struct CustomEmojiModel::Private {
Quotient::Connection *conn = nullptr;
QPointer<NeoChatConnection> connection;
QList<CustomEmoji> emojies;
};

View File

@@ -11,9 +11,10 @@
#include <KLocalizedString>
#include <Quotient/csapi/device_management.h>
#include <Quotient/connection.h>
#include <Quotient/user.h>
#include "neochatconnection.h"
using namespace Quotient;
DevicesModel::DevicesModel(QObject *parent)
@@ -152,12 +153,12 @@ void DevicesModel::setName(const QString &deviceId, const QString &name)
});
}
Connection *DevicesModel::connection() const
NeoChatConnection *DevicesModel::connection() const
{
return m_connection;
}
void DevicesModel::setConnection(Connection *connection)
void DevicesModel::setConnection(NeoChatConnection *connection)
{
if (m_connection) {
disconnect(m_connection, nullptr, this, nullptr);

View File

@@ -9,10 +9,7 @@
#include <Quotient/csapi/definitions/client_device.h>
namespace Quotient
{
class Connection;
}
class NeoChatConnection;
/**
* @class DevicesModel
@@ -31,7 +28,7 @@ class DevicesModel : public QAbstractListModel
/**
* @brief The current connection that the model is getting its devices from.
*/
Q_PROPERTY(Quotient::Connection *connection READ connection WRITE setConnection NOTIFY connectionChanged REQUIRED)
Q_PROPERTY(NeoChatConnection *connection READ connection WRITE setConnection NOTIFY connectionChanged REQUIRED)
public:
/**
@@ -88,9 +85,8 @@ public:
explicit DevicesModel(QObject *parent = nullptr);
[[nodiscard]] Quotient::Connection *connection() const;
void setConnection(Quotient::Connection *connection);
[[nodiscard]] NeoChatConnection *connection() const;
void setConnection(NeoChatConnection *connection);
Q_SIGNALS:
void connectionChanged();
@@ -99,5 +95,5 @@ Q_SIGNALS:
private:
void fetchDevices();
QList<Quotient::Device> m_devices;
QPointer<Quotient::Connection> m_connection;
QPointer<NeoChatConnection> m_connection;
};

View File

@@ -7,7 +7,6 @@
#include "neochatconfig.h"
#include <Quotient/connection.h>
#include <Quotient/csapi/rooms.h>
#include <Quotient/events/redactionevent.h>
#include <Quotient/events/roommessageevent.h>

View File

@@ -3,7 +3,6 @@
#include "notificationsmodel.h"
#include <Quotient/connection.h>
#include <Quotient/events/event.h>
#include <Quotient/uri.h>

View File

@@ -3,8 +3,7 @@
#include "publicroomlistmodel.h"
#include <Quotient/connection.h>
#include "neochatconnection.h"
#include "publicroomlist_logging.h"
using namespace Quotient;
@@ -14,14 +13,14 @@ PublicRoomListModel::PublicRoomListModel(QObject *parent)
{
}
Quotient::Connection *PublicRoomListModel::connection() const
NeoChatConnection *PublicRoomListModel::connection() const
{
return m_connection;
}
void PublicRoomListModel::setConnection(Connection *conn)
void PublicRoomListModel::setConnection(NeoChatConnection *connection)
{
if (m_connection == conn) {
if (m_connection == connection) {
return;
}
@@ -38,7 +37,7 @@ void PublicRoomListModel::setConnection(Connection *conn)
endResetModel();
m_connection = conn;
m_connection = connection;
if (job) {
job->abandon();

View File

@@ -9,10 +9,7 @@
#include <Quotient/csapi/list_public_rooms.h>
namespace Quotient
{
class Connection;
}
class NeoChatConnection;
/**
* @class PublicRoomListModel
@@ -33,7 +30,7 @@ class PublicRoomListModel : public QAbstractListModel
/**
* @brief The current connection that the model is getting its rooms from.
*/
Q_PROPERTY(Quotient::Connection *connection READ connection WRITE setConnection NOTIFY connectionChanged)
Q_PROPERTY(NeoChatConnection *connection READ connection WRITE setConnection NOTIFY connectionChanged)
/**
* @brief The server to get the public room list from.
@@ -95,8 +92,8 @@ public:
*/
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
[[nodiscard]] Quotient::Connection *connection() const;
void setConnection(Quotient::Connection *conn);
[[nodiscard]] NeoChatConnection *connection() const;
void setConnection(NeoChatConnection *connection);
[[nodiscard]] QString server() const;
void setServer(const QString &value);
@@ -117,7 +114,7 @@ public:
Q_INVOKABLE void search(int limit = 50);
private:
QPointer<Quotient::Connection> m_connection = nullptr;
QPointer<NeoChatConnection> m_connection = nullptr;
QString m_server;
QString m_searchText;
bool m_showOnlySpaces = false;

View File

@@ -5,13 +5,13 @@
#include <QDebug>
#include <Quotient/connection.h>
#include <Quotient/converters.h>
#include <Quotient/csapi/definitions/push_ruleset.h>
#include <Quotient/csapi/pushrules.h>
#include <Quotient/jobs/basejob.h>
#include "neochatconfig.h"
#include "neochatconnection.h"
#include <KLazyLocalizedString>
@@ -454,7 +454,7 @@ void PushRuleModel::setConnection(NeoChatConnection *connection)
Q_EMIT connectionChanged();
if (m_connection) {
connect(m_connection, &Quotient::Connection::accountDataChanged, this, &PushRuleModel::updateNotificationRules);
connect(m_connection, &NeoChatConnection::accountDataChanged, this, &PushRuleModel::updateNotificationRules);
updateNotificationRules(QStringLiteral("m.push_rules"));
}
}

View File

@@ -126,7 +126,7 @@ private Q_SLOTS:
private:
PushRuleAction::Action m_defaultKeywordAction;
QList<Rule> m_rules;
NeoChatConnection *m_connection;
QPointer<NeoChatConnection> m_connection;
void setRules(QList<Quotient::PushRule> rules, PushRuleKind::Kind kind);

View File

@@ -25,12 +25,12 @@ RoomListModel::RoomListModel(QObject *parent)
RoomListModel::~RoomListModel() = default;
Quotient::Connection *RoomListModel::connection() const
NeoChatConnection *RoomListModel::connection() const
{
return m_connection;
}
void RoomListModel::setConnection(Connection *connection)
void RoomListModel::setConnection(NeoChatConnection *connection)
{
if (connection == m_connection) {
return;

View File

@@ -12,10 +12,11 @@ class NeoChatRoom;
namespace Quotient
{
class Connection;
class Room;
}
class NeoChatConnection;
/**
* @class RoomListModel
*
@@ -29,7 +30,7 @@ class RoomListModel : public QAbstractListModel
/**
* @brief The current connection that the model is getting its rooms from.
*/
Q_PROPERTY(Quotient::Connection *connection READ connection WRITE setConnection NOTIFY connectionChanged)
Q_PROPERTY(NeoChatConnection *connection READ connection WRITE setConnection NOTIFY connectionChanged)
public:
/**
@@ -60,8 +61,8 @@ public:
explicit RoomListModel(QObject *parent = nullptr);
~RoomListModel() override;
[[nodiscard]] Quotient::Connection *connection() const;
void setConnection(Quotient::Connection *connection);
[[nodiscard]] NeoChatConnection *connection() const;
void setConnection(NeoChatConnection *connection);
/**
* @brief Get the given role value at the given index.
@@ -109,7 +110,7 @@ private Q_SLOTS:
void refresh(NeoChatRoom *room, const QList<int> &roles = {});
private:
Quotient::Connection *m_connection = nullptr;
QPointer<NeoChatConnection> m_connection;
QList<NeoChatRoom *> m_rooms;
QString m_activeSpaceId;

View File

@@ -3,7 +3,6 @@
#include "roomtreemodel.h"
#include <Quotient/connection.h>
#include <Quotient/room.h>
#include "eventhandler.h"

View File

@@ -10,7 +10,6 @@
#include <QGuiApplication>
#include <Quotient/connection.h>
#include <Quotient/events/stickerevent.h>
#include <KLocalizedString>

View File

@@ -3,8 +3,6 @@
#include "serverlistmodel.h"
#include <Quotient/connection.h>
#include <QDebug>
#include <KConfig>

View File

@@ -110,7 +110,7 @@ Q_SIGNALS:
private:
QList<Server> m_servers;
QPointer<Quotient::QueryPublicRoomsJob> m_checkServerJob = nullptr;
NeoChatConnection *m_connection = nullptr;
QPointer<NeoChatConnection> m_connection;
void initialize();
};

View File

@@ -5,6 +5,8 @@
#include "roomlistmodel.h"
#include "neochatconnection.h"
SortFilterRoomListModel::SortFilterRoomListModel(RoomListModel *sourceModel, QObject *parent)
: QSortFilterProxyModel(parent)
{

View File

@@ -3,7 +3,6 @@
#include "spacechildrenmodel.h"
#include <Quotient/connection.h>
#include <Quotient/jobs/basejob.h>
#include <Quotient/room.h>
@@ -47,7 +46,7 @@ void SpaceChildrenModel::setSpace(NeoChatRoom *space)
}
auto connection = m_space->connection();
connect(connection, &Quotient::Connection::loadedRoomState, this, [this](Quotient::Room *room) {
connect(connection, &NeoChatConnection::loadedRoomState, this, [this](Quotient::Room *room) {
if (m_pendingChildren.contains(room->name())) {
m_pendingChildren.removeAll(room->name());
refreshModel();

View File

@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: 2023 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 <QPointer>
#include <Quotient/csapi/space_hierarchy.h>
#include <Quotient/events/stateevent.h>
@@ -149,7 +151,7 @@ public:
bool isSuggested() const;
private:
NeoChatConnection *m_connection;
QPointer<NeoChatConnection> m_connection;
std::vector<std::unique_ptr<SpaceTreeItem>> m_children;
SpaceTreeItem *m_parentItem;

View File

@@ -3,9 +3,10 @@
#include "userdirectorylistmodel.h"
#include <Quotient/connection.h>
#include <Quotient/room.h>
#include "neochatconnection.h"
using namespace Quotient;
UserDirectoryListModel::UserDirectoryListModel(QObject *parent)
@@ -13,14 +14,14 @@ UserDirectoryListModel::UserDirectoryListModel(QObject *parent)
{
}
Quotient::Connection *UserDirectoryListModel::connection() const
NeoChatConnection *UserDirectoryListModel::connection() const
{
return m_connection;
}
void UserDirectoryListModel::setConnection(Connection *conn)
void UserDirectoryListModel::setConnection(NeoChatConnection *connection)
{
if (m_connection == conn) {
if (m_connection == connection) {
return;
}
@@ -35,7 +36,7 @@ void UserDirectoryListModel::setConnection(Connection *conn)
endResetModel();
m_connection = conn;
m_connection = connection;
Q_EMIT connectionChanged();
if (m_job) {

View File

@@ -9,10 +9,7 @@
#include <Quotient/csapi/users.h>
namespace Quotient
{
class Connection;
}
class NeoChatConnection;
/**
* @class UserDirectoryListModel
@@ -32,7 +29,7 @@ class UserDirectoryListModel : public QAbstractListModel
/**
* @brief The current connection that the model is getting users from.
*/
Q_PROPERTY(Quotient::Connection *connection READ connection WRITE setConnection NOTIFY connectionChanged)
Q_PROPERTY(NeoChatConnection *connection READ connection WRITE setConnection NOTIFY connectionChanged)
/**
* @brief The text to search the public room list for.
@@ -57,8 +54,8 @@ public:
explicit UserDirectoryListModel(QObject *parent = nullptr);
[[nodiscard]] Quotient::Connection *connection() const;
void setConnection(Quotient::Connection *conn);
[[nodiscard]] NeoChatConnection *connection() const;
void setConnection(NeoChatConnection *connection);
[[nodiscard]] QString searchText() const;
void setSearchText(const QString &searchText);
@@ -99,7 +96,7 @@ Q_SIGNALS:
void searchingChanged();
private:
Quotient::Connection *m_connection = nullptr;
QPointer<NeoChatConnection> m_connection;
QString m_searchText;
bool attempted = false;

View File

@@ -5,7 +5,6 @@
#include <QGuiApplication>
#include <Quotient/connection.h>
#include <Quotient/events/roompowerlevelsevent.h>
#include "neochatroom.h"

View File

@@ -170,7 +170,7 @@ void Registration::testHomeserver()
delete m_connection;
}
m_connection = new Connection(this);
m_connection = new NeoChatConnection(this);
m_connection->resolveServer("@user:%1"_ls.arg(m_homeserver));
connectSingleShot(m_connection.data(), &Connection::loginFlowsChanged, this, [this]() {
if (m_testServerJob) {

View File

@@ -13,17 +13,16 @@
#include <Quotient/csapi/registration.h>
#include <Quotient/connection.h>
#include <Quotient/jobs/basejob.h>
#include <Quotient/util.h>
namespace Quotient
{
class Connection;
class CheckUsernameAvailabilityJob;
}
class NeoChatConnection;
class NeoChatRegisterJob : public Quotient::BaseJob
{
public:
@@ -159,7 +158,7 @@ private:
QPointer<Quotient::CheckUsernameAvailabilityJob> m_usernameJob;
QPointer<NeoChatRegisterJob> m_testServerJob;
QList<QList<QString>> m_flows;
QPointer<Quotient::Connection> m_connection;
QPointer<NeoChatConnection> m_connection;
void testHomeserver();
void testUsername();

View File

@@ -150,7 +150,7 @@ void RoomManager::resolveResource(const QString &idOrUri, const QString &action)
Q_ASSERT(result == Quotient::UriResolved);
if (uri.type() == Uri::RoomAlias || uri.type() == Uri::RoomId) {
connectSingleShot(m_connection, &Connection::newRoom, this, [this, uri](Room *room) {
connectSingleShot(m_connection.get(), &NeoChatConnection::newRoom, this, [this, uri](Room *room) {
resolveResource(room->id());
});
}
@@ -303,7 +303,7 @@ void RoomManager::joinRoom(Quotient::Connection *account, const QString &roomAli
auto job = account->joinRoom(roomAliasOrId, viaServers);
connectSingleShot(job, &Quotient::BaseJob::finished, this, [this, account](Quotient::BaseJob *finish) {
if (finish->status() == Quotient::BaseJob::Success) {
connectSingleShot(account, &Quotient::Connection::newRoom, this, [this](Quotient::Room *room) {
connectSingleShot(account, &NeoChatConnection::newRoom, this, [this](Quotient::Room *room) {
resolveResource(room->id());
});
} else {
@@ -312,7 +312,7 @@ void RoomManager::joinRoom(Quotient::Connection *account, const QString &roomAli
});
}
void RoomManager::knockRoom(Quotient::Connection *account, const QString &roomAliasOrId, const QString &reason, const QStringList &viaServers)
void RoomManager::knockRoom(NeoChatConnection *account, const QString &roomAliasOrId, const QString &reason, const QStringList &viaServers)
{
auto *const job = account->callApi<KnockRoomJob>(roomAliasOrId, viaServers, reason);
// Upon completion, ensure a room object is created in case it hasn't come
@@ -321,7 +321,7 @@ void RoomManager::knockRoom(Quotient::Connection *account, const QString &roomAl
// to overtake clients that may add their own slots to finished().
connectSingleShot(job, &BaseJob::finished, this, [this, job, account] {
if (job->status() == Quotient::BaseJob::Success) {
connectSingleShot(account, &Quotient::Connection::newRoom, this, [this](Quotient::Room *room) {
connectSingleShot(account, &NeoChatConnection::newRoom, this, [this](Quotient::Room *room) {
Q_EMIT currentRoom()->showMessage(NeoChatRoom::Info, i18n("You requested to join '%1'", room->name()));
});
} else {

View File

@@ -192,7 +192,7 @@ public:
* See https://spec.matrix.org/latest/client-server-api/#knocking-on-rooms for
* knocking on rooms.
*/
void knockRoom(Quotient::Connection *account, const QString &roomAliasOrId, const QString &reason, const QStringList &viaServers);
void knockRoom(NeoChatConnection *account, const QString &roomAliasOrId, const QString &reason, const QStringList &viaServers);
/**
* @brief Show a media item maximized.
@@ -358,7 +358,7 @@ private:
TimelineModel *m_timelineModel;
MessageFilterModel *m_messageFilterModel;
MediaMessageFilterModel *m_mediaMessageFilterModel;
NeoChatConnection *m_connection;
QPointer<NeoChatConnection> m_connection;
void setCurrentRoom(const QString &roomId);

View File

@@ -116,5 +116,5 @@ private:
QHash<QString, Quotient::Omittable<QString>> m_nextBatchTokens;
void populateSpaceHierarchy(const QString &spaceId);
void addBatch(const QString &spaceId, Quotient::GetSpaceHierarchyJob *job);
NeoChatConnection *m_connection;
QPointer<NeoChatConnection> m_connection;
};

View File

@@ -3,6 +3,8 @@
#include "utils.h"
#include <Quotient/connection.h>
#include <QJsonDocument>
using namespace Quotient;

View File

@@ -9,7 +9,6 @@
#include <QQmlEngine>
#include <QRegularExpression>
#include <Quotient/connection.h>
#include <Quotient/user.h>
class QmlUtils : public QObject