aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2019-08-25 18:56:03 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2020-03-25 22:35:23 +0100
commit10b5ab9e13c46f275c3b1e567fb6a6421b103e6e (patch)
tree8fdb92bafcb61f56ffac5dc2e3dde01d494d2d1c /lib
parentb4748f1a31808d21aeb359b21aedd3b483b535d1 (diff)
downloadlibquotient-10b5ab9e13c46f275c3b1e567fb6a6421b103e6e.tar.gz
libquotient-10b5ab9e13c46f275c3b1e567fb6a6421b103e6e.zip
setAvatarForRoom: try recover from otherAvatars inconsistency
Cherry-pick of what seems to be a fix for #347.
Diffstat (limited to 'lib')
-rw-r--r--lib/user.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/user.cpp b/lib/user.cpp
index 17db5760..535551cf 100644
--- a/lib/user.cpp
+++ b/lib/user.cpp
@@ -165,19 +165,26 @@ 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)