diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-08-25 18:56:03 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-08-26 19:20:31 +0900 |
commit | c3b69fb217c2de0f3b73051b36d4b1e190ef493e (patch) | |
tree | c7ed9a21198c786645cff70282234839639672b7 /lib | |
parent | e997f214562acf30ae8d4ea7132dde6e583ac6fe (diff) | |
download | libquotient-c3b69fb217c2de0f3b73051b36d4b1e190ef493e.tar.gz libquotient-c3b69fb217c2de0f3b73051b36d4b1e190ef493e.zip |
setAvatarForRoom: try recover from otherAvatars inconsistency
Hopefully manages cases like #347 in a better way.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/user.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/user.cpp b/lib/user.cpp index 5dea3942..641f6a6b 100644 --- a/lib/user.cpp +++ b/lib/user.cpp @@ -154,10 +154,11 @@ void User::Private::setAvatarForRoom(const Room* r, const QUrl& newUrl, } if (newUrl != mostUsedAvatar.url()) { // Check if the new avatar is about to become most used. - if (avatarsToRooms.count(newUrl) >= totalRooms - avatarsToRooms.size()) { + const auto newUrlUsage = avatarsToRooms.count(newUrl); + if (newUrlUsage >= totalRooms - avatarsToRooms.size()) { QElapsedTimer et; if (totalRooms > MIN_JOINED_ROOMS_TO_LOG) { - qCDebug(MAIN) + qCInfo(MAIN) << "Switching the most used avatar of user" << userId << "from" << mostUsedAvatar.url().toDisplayString() << "to" << newUrl.toDisplayString(); @@ -165,7 +166,15 @@ void User::Private::setAvatarForRoom(const Room* r, const QUrl& newUrl, } avatarsToRooms.remove(newUrl); auto nextMostUsedIt = otherAvatar(newUrl); - Q_ASSERT(nextMostUsedIt != otherAvatars.end()); + if (nextMostUsedIt == otherAvatars.end()) { + qCCritical(MAIN) + << userId << "doesn't have" << newUrl.toDisplayString() + << "in otherAvatars though it seems to be used in" + << newUrlUsage << "rooms"; + Q_ASSERT(false); + otherAvatars.emplace_back(makeAvatar(newUrl)); + nextMostUsedIt = otherAvatars.end() - 1; + } std::swap(mostUsedAvatar, *nextMostUsedIt); const auto& roomMap = connection->roomMap(); for (const auto* r1 : roomMap) |