aboutsummaryrefslogtreecommitdiff
path: root/lib/user.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/user.cpp')
-rw-r--r--lib/user.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/lib/user.cpp b/lib/user.cpp
index 17db5760..c51354a0 100644
--- a/lib/user.cpp
+++ b/lib/user.cpp
@@ -118,8 +118,7 @@ void User::Private::setNameForRoom(const Room* r, QString newName,
et.start();
}
- const auto& roomMap = connection->roomMap();
- for (auto* r1: roomMap)
+ for (auto* r1: connection->allRooms())
if (nameForRoom(r1) == mostUsedName)
otherNames.insert(mostUsedName, r1);
@@ -165,22 +164,28 @@ 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) << "Switching the most used avatar of user" << userId
- << "from" << mostUsedAvatar.url().toDisplayString()
- << "to" << newUrl.toDisplayString();
+ if (totalRooms > MIN_JOINED_ROOMS_TO_LOG) {
+ qCInfo(MAIN) << "Switching the most used avatar of user" << userId
+ << "from" << mostUsedAvatar.url().toDisplayString()
+ << "to" << newUrl.toDisplayString();
et.start();
}
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)
+ for (const auto* r1: connection->allRooms())
if (avatarUrlForRoom(r1) == nextMostUsedIt->url())
avatarsToRooms.insert(nextMostUsedIt->url(), r1);