aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-01-25 14:05:28 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-01-25 14:05:28 +0900
commit80f75c9b5c6642e8c02e626f991e2ed620a2dc4f (patch)
tree0bcf3c384f4dd753c5d7eaa62d294287334387af
parent6ab89ce02e450605cebd432d2113a3115d0cf8c1 (diff)
downloadlibquotient-80f75c9b5c6642e8c02e626f991e2ed620a2dc4f.tar.gz
libquotient-80f75c9b5c6642e8c02e626f991e2ed620a2dc4f.zip
Connection::provideRoom: assert no empty ids
Bonus: slightly more accurate comment in Connection::forgetRoom
-rw-r--r--connection.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/connection.cpp b/connection.cpp
index e182f9d9..8cdaa3dd 100644
--- a/connection.cpp
+++ b/connection.cpp
@@ -59,6 +59,7 @@ class Connection::Private
// separately so we should, e.g., keep objects for Invite and
// Leave state of the same room.
QHash<QPair<QString, bool>, Room*> roomMap;
+ QVector<QString> justForgottenRoomIds;
QHash<QString, User*> userMap;
QString userId;
@@ -383,16 +384,17 @@ ForgetRoomJob* Connection::forgetRoom(const QString& id)
if (room && room->joinState() != JoinState::Leave)
{
auto leaveJob = room->leaveRoom();
- connect(leaveJob, &BaseJob::success,
- this, [this, forgetJob] { forgetJob->start(connectionData()); });
+ connect(leaveJob, &BaseJob::success, this, [this, forgetJob, id] {
+ forgetJob->start(connectionData());
+ d->justForgottenRoomIds.push_back(id);
+ });
connect(leaveJob, &BaseJob::failure, forgetJob, &BaseJob::abandon);
}
else
forgetJob->start(connectionData());
connect(forgetJob, &BaseJob::success, this, [this, id]
{
- // If the room happens to be in the map (possible in both forms),
- // delete the found object(s).
+ // If the room is in the map (possibly in both forms), delete all forms.
for (auto f: {false, true})
if (auto r = d->roomMap.take({ id, f }))
{
@@ -479,11 +481,7 @@ const ConnectionData* Connection::connectionData() const
Room* Connection::provideRoom(const QString& id, JoinState joinState)
{
// TODO: This whole function is a strong case for a RoomManager class.
- if (id.isEmpty())
- {
- qCDebug(MAIN) << "Connection::provideRoom() with empty id, doing nothing";
- return nullptr;
- }
+ Q_ASSERT_X(!id.isEmpty(), __FUNCTION__, "Empty room id");
const auto roomKey = qMakePair(id, joinState == JoinState::Invite);
auto* room = d->roomMap.value(roomKey, nullptr);