Port away from commitSingleShot
This commit is contained in:
@@ -106,11 +106,16 @@ Controller::Controller(QObject *parent)
|
||||
connect(connection, &NeoChatConnection::syncDone, this, [connection]() {
|
||||
NotificationsManager::instance().handleNotifications(connection);
|
||||
});
|
||||
connectSingleShot(connection, &NeoChatConnection::syncDone, this, [this, connection] {
|
||||
if (!m_endpoint.isEmpty()) {
|
||||
connection->setupPushNotifications(m_endpoint);
|
||||
}
|
||||
});
|
||||
connect(
|
||||
connection,
|
||||
&NeoChatConnection::syncDone,
|
||||
this,
|
||||
[this, connection] {
|
||||
if (!m_endpoint.isEmpty()) {
|
||||
connection->setupPushNotifications(m_endpoint);
|
||||
}
|
||||
},
|
||||
Qt::SingleShotConnection);
|
||||
}
|
||||
oldAccountCount = m_accountRegistry.size();
|
||||
});
|
||||
|
||||
@@ -54,14 +54,19 @@ void LoginHelper::init()
|
||||
m_connection = new NeoChatConnection();
|
||||
}
|
||||
m_connection->resolveServer(m_matrixId);
|
||||
connectSingleShot(m_connection.get(), &Connection::loginFlowsChanged, this, [this]() {
|
||||
setHomeserverReachable(true);
|
||||
m_testing = false;
|
||||
Q_EMIT testingChanged();
|
||||
m_supportsSso = m_connection->supportsSso();
|
||||
m_supportsPassword = m_connection->supportsPasswordAuth();
|
||||
Q_EMIT loginFlowsChanged();
|
||||
});
|
||||
connect(
|
||||
m_connection.get(),
|
||||
&Connection::loginFlowsChanged,
|
||||
this,
|
||||
[this]() {
|
||||
setHomeserverReachable(true);
|
||||
m_testing = false;
|
||||
Q_EMIT testingChanged();
|
||||
m_supportsSso = m_connection->supportsSso();
|
||||
m_supportsPassword = m_connection->supportsPasswordAuth();
|
||||
Q_EMIT loginFlowsChanged();
|
||||
},
|
||||
Qt::SingleShotConnection);
|
||||
});
|
||||
connect(m_connection, &Connection::connected, this, [this] {
|
||||
Q_EMIT connected();
|
||||
@@ -100,9 +105,14 @@ void LoginHelper::init()
|
||||
Q_EMIT Controller::instance().errorOccured(i18n("Network Error"), std::move(error));
|
||||
});
|
||||
|
||||
connectSingleShot(m_connection.get(), &Connection::syncDone, this, [this]() {
|
||||
Q_EMIT loaded();
|
||||
});
|
||||
connect(
|
||||
m_connection.get(),
|
||||
&Connection::syncDone,
|
||||
this,
|
||||
[this]() {
|
||||
Q_EMIT loaded();
|
||||
},
|
||||
Qt::SingleShotConnection);
|
||||
}
|
||||
|
||||
void LoginHelper::setHomeserverReachable(bool reachable)
|
||||
@@ -182,11 +192,16 @@ QUrl LoginHelper::ssoUrl() const
|
||||
void LoginHelper::loginWithSso()
|
||||
{
|
||||
m_connection->resolveServer(m_matrixId);
|
||||
connectSingleShot(m_connection.get(), &Connection::loginFlowsChanged, this, [this]() {
|
||||
SsoSession *session = m_connection->prepareForSso(m_deviceName);
|
||||
m_ssoUrl = session->ssoUrl();
|
||||
Q_EMIT ssoUrlChanged();
|
||||
});
|
||||
connect(
|
||||
m_connection.get(),
|
||||
&Connection::loginFlowsChanged,
|
||||
this,
|
||||
[this]() {
|
||||
SsoSession *session = m_connection->prepareForSso(m_deviceName);
|
||||
m_ssoUrl = session->ssoUrl();
|
||||
Q_EMIT ssoUrlChanged();
|
||||
},
|
||||
Qt::SingleShotConnection);
|
||||
}
|
||||
|
||||
bool LoginHelper::testing() const
|
||||
|
||||
@@ -321,9 +321,14 @@ void NeoChatConnection::createRoom(const QString &name, const QString &topic, co
|
||||
connect(job, &CreateRoomJob::failure, this, [job] {
|
||||
Q_EMIT Controller::instance().errorOccured(i18n("Room creation failed: %1", job->errorString()), {});
|
||||
});
|
||||
connectSingleShot(this, &Connection::newRoom, this, [](Room *room) {
|
||||
RoomManager::instance().resolveResource(room->id());
|
||||
});
|
||||
connect(
|
||||
this,
|
||||
&Connection::newRoom,
|
||||
this,
|
||||
[](Room *room) {
|
||||
RoomManager::instance().resolveResource(room->id());
|
||||
},
|
||||
Qt::SingleShotConnection);
|
||||
}
|
||||
|
||||
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] {
|
||||
Q_EMIT Controller::instance().errorOccured(i18n("Space creation failed: %1", job->errorString()), {});
|
||||
});
|
||||
connectSingleShot(this, &Connection::newRoom, this, [](Room *room) {
|
||||
RoomManager::instance().resolveResource(room->id());
|
||||
});
|
||||
connect(
|
||||
this,
|
||||
&Connection::newRoom,
|
||||
this,
|
||||
[](Room *room) {
|
||||
RoomManager::instance().resolveResource(room->id());
|
||||
},
|
||||
Qt::SingleShotConnection);
|
||||
}
|
||||
|
||||
bool NeoChatConnection::directChatExists(Quotient::User *user)
|
||||
@@ -384,9 +394,14 @@ void NeoChatConnection::openOrCreateDirectChat(User *user)
|
||||
}
|
||||
}
|
||||
requestDirectChat(user);
|
||||
connectSingleShot(this, &Connection::directChatAvailable, this, [=](auto room) {
|
||||
room->activateEncryption();
|
||||
});
|
||||
connect(
|
||||
this,
|
||||
&Connection::directChatAvailable,
|
||||
this,
|
||||
[=](auto room) {
|
||||
room->activateEncryption();
|
||||
},
|
||||
Qt::SingleShotConnection);
|
||||
}
|
||||
|
||||
qsizetype NeoChatConnection::directChatNotifications() const
|
||||
|
||||
@@ -96,23 +96,28 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS
|
||||
});
|
||||
connect(this, &Room::displaynameChanged, this, &NeoChatRoom::displayNameChanged);
|
||||
|
||||
connectSingleShot(this, &Room::baseStateLoaded, this, [this]() {
|
||||
updatePushNotificationState(QStringLiteral("m.push_rules"));
|
||||
connect(
|
||||
this,
|
||||
&Room::baseStateLoaded,
|
||||
this,
|
||||
[this]() {
|
||||
updatePushNotificationState(QStringLiteral("m.push_rules"));
|
||||
|
||||
Q_EMIT canEncryptRoomChanged();
|
||||
if (this->joinState() != JoinState::Invite) {
|
||||
return;
|
||||
}
|
||||
auto roomMemberEvent = currentState().get<RoomMemberEvent>(localUser()->id());
|
||||
QImage avatar_image;
|
||||
if (roomMemberEvent && !user(roomMemberEvent->senderId())->avatarUrl(this).isEmpty()) {
|
||||
avatar_image = user(roomMemberEvent->senderId())->avatar(128, this);
|
||||
} else {
|
||||
qWarning() << "using this room's avatar";
|
||||
avatar_image = avatar(128);
|
||||
}
|
||||
NotificationsManager::instance().postInviteNotification(this, displayName(), htmlSafeMemberName(roomMemberEvent->senderId()), avatar_image);
|
||||
});
|
||||
Q_EMIT canEncryptRoomChanged();
|
||||
if (this->joinState() != JoinState::Invite) {
|
||||
return;
|
||||
}
|
||||
auto roomMemberEvent = currentState().get<RoomMemberEvent>(localUser()->id());
|
||||
QImage avatar_image;
|
||||
if (roomMemberEvent && !user(roomMemberEvent->senderId())->avatarUrl(this).isEmpty()) {
|
||||
avatar_image = user(roomMemberEvent->senderId())->avatar(128, this);
|
||||
} else {
|
||||
qWarning() << "using this room's avatar";
|
||||
avatar_image = avatar(128);
|
||||
}
|
||||
NotificationsManager::instance().postInviteNotification(this, displayName(), htmlSafeMemberName(roomMemberEvent->senderId()), avatar_image);
|
||||
},
|
||||
Qt::SingleShotConnection);
|
||||
connect(this, &Room::changed, this, [this] {
|
||||
Q_EMIT canEncryptRoomChanged();
|
||||
Q_EMIT parentIdsChanged();
|
||||
|
||||
@@ -112,9 +112,14 @@ void Registration::registerAccount()
|
||||
account.sync();
|
||||
Controller::instance().addConnection(connection);
|
||||
Controller::instance().setActiveConnection(connection);
|
||||
connectSingleShot(connection, &Connection::syncDone, this, []() {
|
||||
Q_EMIT LoginHelper::instance().loaded();
|
||||
});
|
||||
connect(
|
||||
connection,
|
||||
&Connection::syncDone,
|
||||
this,
|
||||
[]() {
|
||||
Q_EMIT LoginHelper::instance().loaded();
|
||||
},
|
||||
Qt::SingleShotConnection);
|
||||
m_connection = nullptr;
|
||||
});
|
||||
|
||||
@@ -172,28 +177,33 @@ void Registration::testHomeserver()
|
||||
|
||||
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) {
|
||||
delete m_testServerJob;
|
||||
}
|
||||
m_testServerJob = m_connection->callApi<NeoChatRegisterJob>("user"_ls, none, "user"_ls, QString(), QString(), QString(), false);
|
||||
connect(m_testServerJob.data(), &BaseJob::finished, this, [this]() {
|
||||
if (m_testServerJob->error() == BaseJob::StatusCode::ContentAccessError) {
|
||||
setStatus(ServerNoRegistration);
|
||||
return;
|
||||
connect(
|
||||
m_connection.data(),
|
||||
&Connection::loginFlowsChanged,
|
||||
this,
|
||||
[this]() {
|
||||
if (m_testServerJob) {
|
||||
delete m_testServerJob;
|
||||
}
|
||||
if (m_testServerJob->status().code != 106) {
|
||||
setStatus(InvalidServer);
|
||||
return;
|
||||
}
|
||||
if (!m_username.isEmpty()) {
|
||||
setStatus(TestingUsername);
|
||||
testUsername();
|
||||
} else {
|
||||
setStatus(NoUsername);
|
||||
}
|
||||
});
|
||||
});
|
||||
m_testServerJob = m_connection->callApi<NeoChatRegisterJob>("user"_ls, none, "user"_ls, QString(), QString(), QString(), false);
|
||||
connect(m_testServerJob.data(), &BaseJob::finished, this, [this]() {
|
||||
if (m_testServerJob->error() == BaseJob::StatusCode::ContentAccessError) {
|
||||
setStatus(ServerNoRegistration);
|
||||
return;
|
||||
}
|
||||
if (m_testServerJob->status().code != 106) {
|
||||
setStatus(InvalidServer);
|
||||
return;
|
||||
}
|
||||
if (!m_username.isEmpty()) {
|
||||
setStatus(TestingUsername);
|
||||
testUsername();
|
||||
} else {
|
||||
setStatus(NoUsername);
|
||||
}
|
||||
});
|
||||
},
|
||||
Qt::SingleShotConnection);
|
||||
}
|
||||
|
||||
void Registration::setUsername(const QString &username)
|
||||
|
||||
@@ -150,9 +150,14 @@ 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.get(), &NeoChatConnection::newRoom, this, [this, uri](Room *room) {
|
||||
resolveResource(room->id());
|
||||
});
|
||||
connect(
|
||||
m_connection.get(),
|
||||
&NeoChatConnection::newRoom,
|
||||
this,
|
||||
[this, uri](Room *room) {
|
||||
resolveResource(room->id());
|
||||
},
|
||||
Qt::SingleShotConnection);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -303,18 +308,32 @@ void RoomManager::joinRoom(Quotient::Connection *account, const QString &roomAli
|
||||
{
|
||||
auto job = account->joinRoom(roomAliasOrId, viaServers);
|
||||
#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
|
||||
connectSingleShot(job, &Quotient::BaseJob::finished, this, [this, account](Quotient::BaseJob *finish) {
|
||||
connect(
|
||||
job,
|
||||
&Quotient::BaseJob::finished,
|
||||
this,
|
||||
[this, account](Quotient::BaseJob *finish) {
|
||||
#endif
|
||||
if (finish->status() == Quotient::BaseJob::Success) {
|
||||
connectSingleShot(account, &NeoChatConnection::newRoom, this, [this](Quotient::Room *room) {
|
||||
resolveResource(room->id());
|
||||
});
|
||||
} else {
|
||||
Q_EMIT warning(i18n("Failed to join room"), finish->errorString());
|
||||
}
|
||||
});
|
||||
if (finish->status() == Quotient::BaseJob::Success) {
|
||||
connect(
|
||||
account,
|
||||
&NeoChatConnection::newRoom,
|
||||
this,
|
||||
[this](Quotient::Room *room) {
|
||||
resolveResource(room->id());
|
||||
},
|
||||
Qt::SingleShotConnection);
|
||||
} else {
|
||||
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)
|
||||
@@ -325,18 +344,32 @@ void RoomManager::knockRoom(NeoChatConnection *account, const QString &roomAlias
|
||||
// create it in Join state. finished() is used here instead of success()
|
||||
// to overtake clients that may add their own slots to finished().
|
||||
#if Quotient_VERSION_MINOR > 8
|
||||
connectSingleShot(job.get(), &BaseJob::finished, this, [this, job, account] {
|
||||
connect(
|
||||
job.get(),
|
||||
&BaseJob::finished,
|
||||
this,
|
||||
[this, job, account] {
|
||||
#else
|
||||
connectSingleShot(job, &BaseJob::finished, this, [this, job, account] {
|
||||
connect(
|
||||
job,
|
||||
&BaseJob::finished,
|
||||
this,
|
||||
[this, job, account] {
|
||||
#endif
|
||||
if (job->status() == Quotient::BaseJob::Success) {
|
||||
connectSingleShot(account, &NeoChatConnection::newRoom, this, [this](Quotient::Room *room) {
|
||||
Q_EMIT currentRoom()->showMessage(NeoChatRoom::Info, i18n("You requested to join '%1'", room->name()));
|
||||
});
|
||||
} else {
|
||||
Q_EMIT warning(i18n("Failed to request joining room"), job->errorString());
|
||||
}
|
||||
});
|
||||
if (job->status() == Quotient::BaseJob::Success) {
|
||||
connect(
|
||||
account,
|
||||
&NeoChatConnection::newRoom,
|
||||
this,
|
||||
[this](Quotient::Room *room) {
|
||||
Q_EMIT currentRoom() -> showMessage(NeoChatRoom::Info, i18n("You requested to join '%1'", room->name()));
|
||||
},
|
||||
Qt::SingleShotConnection);
|
||||
} else {
|
||||
Q_EMIT warning(i18n("Failed to request joining room"), job->errorString());
|
||||
}
|
||||
},
|
||||
Qt::SingleShotConnection);
|
||||
}
|
||||
|
||||
bool RoomManager::visitNonMatrix(const QUrl &url)
|
||||
|
||||
@@ -32,11 +32,16 @@ void SpaceHierarchyCache::cacheSpaceHierarchy()
|
||||
if (neoChatRoom->isSpace()) {
|
||||
populateSpaceHierarchy(neoChatRoom->id());
|
||||
} else {
|
||||
connectSingleShot(neoChatRoom, &Room::baseStateLoaded, neoChatRoom, [this, neoChatRoom]() {
|
||||
if (neoChatRoom->isSpace()) {
|
||||
populateSpaceHierarchy(neoChatRoom->id());
|
||||
}
|
||||
});
|
||||
connect(
|
||||
neoChatRoom,
|
||||
&Room::baseStateLoaded,
|
||||
neoChatRoom,
|
||||
[this, neoChatRoom]() {
|
||||
if (neoChatRoom->isSpace()) {
|
||||
populateSpaceHierarchy(neoChatRoom->id());
|
||||
}
|
||||
},
|
||||
Qt::SingleShotConnection);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
connectSingleShot(room, &Quotient::Room::baseStateLoaded, this, [this, room]() {
|
||||
const auto neoChatRoom = static_cast<NeoChatRoom *>(room);
|
||||
if (neoChatRoom->isSpace()) {
|
||||
populateSpaceHierarchy(neoChatRoom->id());
|
||||
}
|
||||
});
|
||||
connect(
|
||||
room,
|
||||
&Quotient::Room::baseStateLoaded,
|
||||
this,
|
||||
[this, room]() {
|
||||
const auto neoChatRoom = static_cast<NeoChatRoom *>(room);
|
||||
if (neoChatRoom->isSpace()) {
|
||||
populateSpaceHierarchy(neoChatRoom->id());
|
||||
}
|
||||
},
|
||||
Qt::SingleShotConnection);
|
||||
}
|
||||
|
||||
void SpaceHierarchyCache::removeSpaceFromHierarchy(Quotient::Room *room)
|
||||
|
||||
Reference in New Issue
Block a user