From ee484b72c461cdb1c87573d91ace2f4f953301dc Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Sun, 3 Mar 2024 17:20:28 +0100 Subject: [PATCH] Improve mock --- Quotient/connection.cpp | 34 ++++++++++++++++++++++++---------- Quotient/connection.h | 6 ++++++ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Quotient/connection.cpp b/Quotient/connection.cpp index 026f50c18..f7df194de 100644 --- a/Quotient/connection.cpp +++ b/Quotient/connection.cpp @@ -1367,6 +1367,21 @@ const ConnectionData* Connection::connectionData() const return d->data.get(); } +void Connection::addRoom(Room *room, bool invite) +{ + const std::pair roomKey { room->id(), invite }; + d->roomMap.insert(roomKey, room); + connect(room, &Room::beforeDestruction, this, + &Connection::aboutToDeleteRoom); + connect(room, &Room::baseStateLoaded, this, [this, room] { + emit loadedRoomState(room); + if (d->capabilities.roomVersions) + room->checkVersion(); + // Otherwise, the version will be checked in reloadCapabilities() + }); + emit newRoom(room); +} + Room* Connection::provideRoom(const QString& id, Omittable joinState) { // TODO: This whole function is a strong case for a RoomManager class. @@ -1397,16 +1412,7 @@ Room* Connection::provideRoom(const QString& id, Omittable joinState) qCCritical(MAIN) << "Failed to create a room" << id; return nullptr; } - d->roomMap.insert(roomKey, room); - connect(room, &Room::beforeDestruction, this, - &Connection::aboutToDeleteRoom); - connect(room, &Room::baseStateLoaded, this, [this, room] { - emit loadedRoomState(room); - if (d->capabilities.roomVersions) - room->checkVersion(); - // Otherwise, the version will be checked in reloadCapabilities() - }); - emit newRoom(room); + addRoom(room, roomKey.second); } if (!joinState) return room; @@ -1902,6 +1908,14 @@ bool Connection::isKnownE2eeCapableDevice(const QString& userId, const QString& #endif +Connection* Connection::makeMockConnection(Connection *c, const QString& mxId, + bool enableEncryption) +{ + c->enableEncryption(enableEncryption); + c->d->completeSetup(mxId, true); + return c; +} + Connection* Connection::makeMockConnection(const QString& mxId, bool enableEncryption) { diff --git a/Quotient/connection.h b/Quotient/connection.h index 2fb01b173..b8e565ff7 100644 --- a/Quotient/connection.h +++ b/Quotient/connection.h @@ -760,6 +760,9 @@ public Q_SLOTS: static Connection* makeMockConnection(const QString& mxId, bool enableEncryption = E2EE_Enabled); + static Connection* makeMockConnection(Connection *connection, const QString& mxId, + bool enableEncryption = E2EE_Enabled); + Q_SIGNALS: //! \brief Initial server resolution has failed //! @@ -947,6 +950,9 @@ public Q_SLOTS: Room* provideRoom(const QString& roomId, Omittable joinState = none); + //! Add room to the connection + void addRoom(Room *room, bool invite = false); + //! Process sync data from a successful sync request void onSyncSuccess(SyncData&& data, bool fromCache = false);