Port away from commitSingleShot

This commit is contained in:
Tobias Fella
2024-06-08 15:39:27 +02:00
parent 91109ca845
commit 29972b5867
7 changed files with 197 additions and 104 deletions

View File

@@ -106,11 +106,16 @@ Controller::Controller(QObject *parent)
connect(connection, &NeoChatConnection::syncDone, this, [connection]() { connect(connection, &NeoChatConnection::syncDone, this, [connection]() {
NotificationsManager::instance().handleNotifications(connection); NotificationsManager::instance().handleNotifications(connection);
}); });
connectSingleShot(connection, &NeoChatConnection::syncDone, this, [this, connection] { connect(
connection,
&NeoChatConnection::syncDone,
this,
[this, connection] {
if (!m_endpoint.isEmpty()) { if (!m_endpoint.isEmpty()) {
connection->setupPushNotifications(m_endpoint); connection->setupPushNotifications(m_endpoint);
} }
}); },
Qt::SingleShotConnection);
} }
oldAccountCount = m_accountRegistry.size(); oldAccountCount = m_accountRegistry.size();
}); });

View File

@@ -54,14 +54,19 @@ void LoginHelper::init()
m_connection = new NeoChatConnection(); m_connection = new NeoChatConnection();
} }
m_connection->resolveServer(m_matrixId); m_connection->resolveServer(m_matrixId);
connectSingleShot(m_connection.get(), &Connection::loginFlowsChanged, this, [this]() { connect(
m_connection.get(),
&Connection::loginFlowsChanged,
this,
[this]() {
setHomeserverReachable(true); setHomeserverReachable(true);
m_testing = false; m_testing = false;
Q_EMIT testingChanged(); Q_EMIT testingChanged();
m_supportsSso = m_connection->supportsSso(); m_supportsSso = m_connection->supportsSso();
m_supportsPassword = m_connection->supportsPasswordAuth(); m_supportsPassword = m_connection->supportsPasswordAuth();
Q_EMIT loginFlowsChanged(); Q_EMIT loginFlowsChanged();
}); },
Qt::SingleShotConnection);
}); });
connect(m_connection, &Connection::connected, this, [this] { connect(m_connection, &Connection::connected, this, [this] {
Q_EMIT connected(); Q_EMIT connected();
@@ -100,9 +105,14 @@ void LoginHelper::init()
Q_EMIT Controller::instance().errorOccured(i18n("Network Error"), std::move(error)); Q_EMIT Controller::instance().errorOccured(i18n("Network Error"), std::move(error));
}); });
connectSingleShot(m_connection.get(), &Connection::syncDone, this, [this]() { connect(
m_connection.get(),
&Connection::syncDone,
this,
[this]() {
Q_EMIT loaded(); Q_EMIT loaded();
}); },
Qt::SingleShotConnection);
} }
void LoginHelper::setHomeserverReachable(bool reachable) void LoginHelper::setHomeserverReachable(bool reachable)
@@ -182,11 +192,16 @@ QUrl LoginHelper::ssoUrl() const
void LoginHelper::loginWithSso() void LoginHelper::loginWithSso()
{ {
m_connection->resolveServer(m_matrixId); m_connection->resolveServer(m_matrixId);
connectSingleShot(m_connection.get(), &Connection::loginFlowsChanged, this, [this]() { connect(
m_connection.get(),
&Connection::loginFlowsChanged,
this,
[this]() {
SsoSession *session = m_connection->prepareForSso(m_deviceName); SsoSession *session = m_connection->prepareForSso(m_deviceName);
m_ssoUrl = session->ssoUrl(); m_ssoUrl = session->ssoUrl();
Q_EMIT ssoUrlChanged(); Q_EMIT ssoUrlChanged();
}); },
Qt::SingleShotConnection);
} }
bool LoginHelper::testing() const bool LoginHelper::testing() const

View File

@@ -321,9 +321,14 @@ void NeoChatConnection::createRoom(const QString &name, const QString &topic, co
connect(job, &CreateRoomJob::failure, this, [job] { connect(job, &CreateRoomJob::failure, this, [job] {
Q_EMIT Controller::instance().errorOccured(i18n("Room creation failed: %1", job->errorString()), {}); Q_EMIT Controller::instance().errorOccured(i18n("Room creation failed: %1", job->errorString()), {});
}); });
connectSingleShot(this, &Connection::newRoom, this, [](Room *room) { connect(
this,
&Connection::newRoom,
this,
[](Room *room) {
RoomManager::instance().resolveResource(room->id()); RoomManager::instance().resolveResource(room->id());
}); },
Qt::SingleShotConnection);
} }
void NeoChatConnection::createSpace(const QString &name, const QString &topic, const QString &parent, bool setChildParent) void NeoChatConnection::createSpace(const QString &name, const QString &topic, const QString &parent, bool setChildParent)
@@ -353,9 +358,14 @@ void NeoChatConnection::createSpace(const QString &name, const QString &topic, c
connect(job, &CreateRoomJob::failure, this, [job] { connect(job, &CreateRoomJob::failure, this, [job] {
Q_EMIT Controller::instance().errorOccured(i18n("Space creation failed: %1", job->errorString()), {}); Q_EMIT Controller::instance().errorOccured(i18n("Space creation failed: %1", job->errorString()), {});
}); });
connectSingleShot(this, &Connection::newRoom, this, [](Room *room) { connect(
this,
&Connection::newRoom,
this,
[](Room *room) {
RoomManager::instance().resolveResource(room->id()); RoomManager::instance().resolveResource(room->id());
}); },
Qt::SingleShotConnection);
} }
bool NeoChatConnection::directChatExists(Quotient::User *user) bool NeoChatConnection::directChatExists(Quotient::User *user)
@@ -384,9 +394,14 @@ void NeoChatConnection::openOrCreateDirectChat(User *user)
} }
} }
requestDirectChat(user); requestDirectChat(user);
connectSingleShot(this, &Connection::directChatAvailable, this, [=](auto room) { connect(
this,
&Connection::directChatAvailable,
this,
[=](auto room) {
room->activateEncryption(); room->activateEncryption();
}); },
Qt::SingleShotConnection);
} }
qsizetype NeoChatConnection::directChatNotifications() const qsizetype NeoChatConnection::directChatNotifications() const

View File

@@ -96,7 +96,11 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS
}); });
connect(this, &Room::displaynameChanged, this, &NeoChatRoom::displayNameChanged); connect(this, &Room::displaynameChanged, this, &NeoChatRoom::displayNameChanged);
connectSingleShot(this, &Room::baseStateLoaded, this, [this]() { connect(
this,
&Room::baseStateLoaded,
this,
[this]() {
updatePushNotificationState(QStringLiteral("m.push_rules")); updatePushNotificationState(QStringLiteral("m.push_rules"));
Q_EMIT canEncryptRoomChanged(); Q_EMIT canEncryptRoomChanged();
@@ -112,7 +116,8 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS
avatar_image = avatar(128); avatar_image = avatar(128);
} }
NotificationsManager::instance().postInviteNotification(this, displayName(), htmlSafeMemberName(roomMemberEvent->senderId()), avatar_image); NotificationsManager::instance().postInviteNotification(this, displayName(), htmlSafeMemberName(roomMemberEvent->senderId()), avatar_image);
}); },
Qt::SingleShotConnection);
connect(this, &Room::changed, this, [this] { connect(this, &Room::changed, this, [this] {
Q_EMIT canEncryptRoomChanged(); Q_EMIT canEncryptRoomChanged();
Q_EMIT parentIdsChanged(); Q_EMIT parentIdsChanged();

View File

@@ -112,9 +112,14 @@ void Registration::registerAccount()
account.sync(); account.sync();
Controller::instance().addConnection(connection); Controller::instance().addConnection(connection);
Controller::instance().setActiveConnection(connection); Controller::instance().setActiveConnection(connection);
connectSingleShot(connection, &Connection::syncDone, this, []() { connect(
connection,
&Connection::syncDone,
this,
[]() {
Q_EMIT LoginHelper::instance().loaded(); Q_EMIT LoginHelper::instance().loaded();
}); },
Qt::SingleShotConnection);
m_connection = nullptr; m_connection = nullptr;
}); });
@@ -172,7 +177,11 @@ void Registration::testHomeserver()
m_connection = new NeoChatConnection(this); m_connection = new NeoChatConnection(this);
m_connection->resolveServer("@user:%1"_ls.arg(m_homeserver)); m_connection->resolveServer("@user:%1"_ls.arg(m_homeserver));
connectSingleShot(m_connection.data(), &Connection::loginFlowsChanged, this, [this]() { connect(
m_connection.data(),
&Connection::loginFlowsChanged,
this,
[this]() {
if (m_testServerJob) { if (m_testServerJob) {
delete m_testServerJob; delete m_testServerJob;
} }
@@ -193,7 +202,8 @@ void Registration::testHomeserver()
setStatus(NoUsername); setStatus(NoUsername);
} }
}); });
}); },
Qt::SingleShotConnection);
} }
void Registration::setUsername(const QString &username) void Registration::setUsername(const QString &username)

View File

@@ -150,9 +150,14 @@ void RoomManager::resolveResource(const QString &idOrUri, const QString &action)
Q_ASSERT(result == Quotient::UriResolved); Q_ASSERT(result == Quotient::UriResolved);
if (uri.type() == Uri::RoomAlias || uri.type() == Uri::RoomId) { if (uri.type() == Uri::RoomAlias || uri.type() == Uri::RoomId) {
connectSingleShot(m_connection.get(), &NeoChatConnection::newRoom, this, [this, uri](Room *room) { connect(
m_connection.get(),
&NeoChatConnection::newRoom,
this,
[this, uri](Room *room) {
resolveResource(room->id()); resolveResource(room->id());
}); },
Qt::SingleShotConnection);
} }
} }
} }
@@ -303,18 +308,32 @@ void RoomManager::joinRoom(Quotient::Connection *account, const QString &roomAli
{ {
auto job = account->joinRoom(roomAliasOrId, viaServers); auto job = account->joinRoom(roomAliasOrId, viaServers);
#if Quotient_VERSION_MINOR > 8 #if Quotient_VERSION_MINOR > 8
connectSingleShot(job.get(), &Quotient::BaseJob::finished, this, [this, account](Quotient::BaseJob *finish) { connect(
job.get(),
&Quotient::BaseJob::finished,
this,
[this, account](Quotient::BaseJob *finish) {
#else #else
connectSingleShot(job, &Quotient::BaseJob::finished, this, [this, account](Quotient::BaseJob *finish) { connect(
job,
&Quotient::BaseJob::finished,
this,
[this, account](Quotient::BaseJob *finish) {
#endif #endif
if (finish->status() == Quotient::BaseJob::Success) { if (finish->status() == Quotient::BaseJob::Success) {
connectSingleShot(account, &NeoChatConnection::newRoom, this, [this](Quotient::Room *room) { connect(
account,
&NeoChatConnection::newRoom,
this,
[this](Quotient::Room *room) {
resolveResource(room->id()); resolveResource(room->id());
}); },
Qt::SingleShotConnection);
} else { } else {
Q_EMIT warning(i18n("Failed to join room"), finish->errorString()); Q_EMIT warning(i18n("Failed to join room"), finish->errorString());
} }
}); },
Qt::SingleShotConnection);
} }
void RoomManager::knockRoom(NeoChatConnection *account, const QString &roomAliasOrId, const QString &reason, const QStringList &viaServers) void RoomManager::knockRoom(NeoChatConnection *account, const QString &roomAliasOrId, const QString &reason, const QStringList &viaServers)
@@ -325,18 +344,32 @@ void RoomManager::knockRoom(NeoChatConnection *account, const QString &roomAlias
// create it in Join state. finished() is used here instead of success() // create it in Join state. finished() is used here instead of success()
// to overtake clients that may add their own slots to finished(). // to overtake clients that may add their own slots to finished().
#if Quotient_VERSION_MINOR > 8 #if Quotient_VERSION_MINOR > 8
connectSingleShot(job.get(), &BaseJob::finished, this, [this, job, account] { connect(
job.get(),
&BaseJob::finished,
this,
[this, job, account] {
#else #else
connectSingleShot(job, &BaseJob::finished, this, [this, job, account] { connect(
job,
&BaseJob::finished,
this,
[this, job, account] {
#endif #endif
if (job->status() == Quotient::BaseJob::Success) { if (job->status() == Quotient::BaseJob::Success) {
connectSingleShot(account, &NeoChatConnection::newRoom, this, [this](Quotient::Room *room) { connect(
account,
&NeoChatConnection::newRoom,
this,
[this](Quotient::Room *room) {
Q_EMIT currentRoom() -> showMessage(NeoChatRoom::Info, i18n("You requested to join '%1'", room->name())); Q_EMIT currentRoom() -> showMessage(NeoChatRoom::Info, i18n("You requested to join '%1'", room->name()));
}); },
Qt::SingleShotConnection);
} else { } else {
Q_EMIT warning(i18n("Failed to request joining room"), job->errorString()); Q_EMIT warning(i18n("Failed to request joining room"), job->errorString());
} }
}); },
Qt::SingleShotConnection);
} }
bool RoomManager::visitNonMatrix(const QUrl &url) bool RoomManager::visitNonMatrix(const QUrl &url)

View File

@@ -32,11 +32,16 @@ void SpaceHierarchyCache::cacheSpaceHierarchy()
if (neoChatRoom->isSpace()) { if (neoChatRoom->isSpace()) {
populateSpaceHierarchy(neoChatRoom->id()); populateSpaceHierarchy(neoChatRoom->id());
} else { } else {
connectSingleShot(neoChatRoom, &Room::baseStateLoaded, neoChatRoom, [this, neoChatRoom]() { connect(
neoChatRoom,
&Room::baseStateLoaded,
neoChatRoom,
[this, neoChatRoom]() {
if (neoChatRoom->isSpace()) { if (neoChatRoom->isSpace()) {
populateSpaceHierarchy(neoChatRoom->id()); populateSpaceHierarchy(neoChatRoom->id());
} }
}); },
Qt::SingleShotConnection);
} }
connect(neoChatRoom, &NeoChatRoom::unreadStatsChanged, this, [this, neoChatRoom]() { connect(neoChatRoom, &NeoChatRoom::unreadStatsChanged, this, [this, neoChatRoom]() {
@@ -97,12 +102,17 @@ void SpaceHierarchyCache::addBatch(const QString &spaceId, Quotient::GetSpaceHie
void SpaceHierarchyCache::addSpaceToHierarchy(Quotient::Room *room) void SpaceHierarchyCache::addSpaceToHierarchy(Quotient::Room *room)
{ {
connectSingleShot(room, &Quotient::Room::baseStateLoaded, this, [this, room]() { connect(
room,
&Quotient::Room::baseStateLoaded,
this,
[this, room]() {
const auto neoChatRoom = static_cast<NeoChatRoom *>(room); const auto neoChatRoom = static_cast<NeoChatRoom *>(room);
if (neoChatRoom->isSpace()) { if (neoChatRoom->isSpace()) {
populateSpaceHierarchy(neoChatRoom->id()); populateSpaceHierarchy(neoChatRoom->id());
} }
}); },
Qt::SingleShotConnection);
} }
void SpaceHierarchyCache::removeSpaceFromHierarchy(Quotient::Room *room) void SpaceHierarchyCache::removeSpaceFromHierarchy(Quotient::Room *room)