Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve mock #723

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions Quotient/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> joinState)
{
// TODO: This whole function is a strong case for a RoomManager class.
Expand Down Expand Up @@ -1397,16 +1412,7 @@ Room* Connection::provideRoom(const QString& id, Omittable<JoinState> 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;
Expand Down Expand Up @@ -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)
{
Expand Down
6 changes: 6 additions & 0 deletions Quotient/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this API looks weird, why is it a static function that's passed an object?

Looking at the neochat MR for this, it seems that we could easily use the existing makeMockConnection function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the issue with the existing function is that it return a Connection * and not a NeoChatConnection *

Copy link
Member

@KitsuneRal KitsuneRal Mar 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AccountRegistry looks like a good place for it? Then you could derive from it and override a virtual function. Or simply making makeMockConnection() a template would also work I guess (would need pulling completeSetup() from Connection::Private to Connection but that's a smaller evil)?

bool enableEncryption = E2EE_Enabled);

Q_SIGNALS:
//! \brief Initial server resolution has failed
//!
Expand Down Expand Up @@ -947,6 +950,9 @@ public Q_SLOTS:
Room* provideRoom(const QString& roomId,
Omittable<JoinState> joinState = none);

//! Add room to the connection
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also mention that this is only for tests and not useful in normal operation

void addRoom(Room *room, bool invite = false);

//! Process sync data from a successful sync request
void onSyncSuccess(SyncData&& data, bool fromCache = false);

Expand Down
Loading