diff options
Diffstat (limited to 'lib/room.cpp')
-rw-r--r-- | lib/room.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/room.cpp b/lib/room.cpp index ab2932bd..a5ed76a8 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -192,7 +192,7 @@ public: // void inviteUser(User* u); // We might get it at some point in time. void insertMemberIntoMap(User* u); - void removeMemberFromMap(const QString& username, User* u); + void removeMemberFromMap(User* u); // This updates the room displayname field (which is the way a room // should be shown in the room list); called whenever the list of @@ -1355,7 +1355,8 @@ Room::Changes Room::Private::setSummary(RoomSummary&& newSummary) void Room::Private::insertMemberIntoMap(User* u) { - const auto userName = u->name(q); + const auto userName = + getCurrentState<RoomMemberEvent>(u->id())->displayName(); // If there is exactly one namesake of the added user, signal member // renaming for that other one because the two should be disambiguated now. const auto namesakes = membersMap.values(userName); @@ -1376,16 +1377,19 @@ void Room::Private::insertMemberIntoMap(User* u) emit q->memberRenamed(namesakes.front()); } -void Room::Private::removeMemberFromMap(const QString& username, User* u) +void Room::Private::removeMemberFromMap(User* u) { + const auto userName = + getCurrentState<RoomMemberEvent>(u->id())->displayName(); + User* namesake = nullptr; - auto namesakes = membersMap.values(username); + auto namesakes = membersMap.values(userName); if (namesakes.size() == 2) { namesake = namesakes.front() == u ? namesakes.back() : namesakes.front(); Q_ASSERT_X(namesake != u, __FUNCTION__, "Room members list is broken"); - emit q->memberAboutToRename(namesake, username); + emit q->memberAboutToRename(namesake, userName); } - membersMap.remove(username, u); + membersMap.remove(userName, u); // If there was one namesake besides the removed user, signal member // renaming for it because it doesn't need to be disambiguated any more. if (namesake) @@ -2446,7 +2450,7 @@ Room::Changes Room::processStateEvent(const RoomEvent& e) case MembershipType::Join: // rename/avatar change or no-op if (rme.displayName() != oldRme->displayName()) { emit memberAboutToRename(u, rme.displayName()); - d->removeMemberFromMap(u->name(this), u); + d->removeMemberFromMap(u); } break; case MembershipType::Invite: @@ -2454,7 +2458,7 @@ Room::Changes Room::processStateEvent(const RoomEvent& e) << rme; [[fallthrough]]; default: // whatever the new membership, it's no more Join - d->removeMemberFromMap(u->name(this), u); + d->removeMemberFromMap(u); emit userRemoved(u); } break; @@ -2755,7 +2759,7 @@ QString Room::Private::calculateDisplayname() const const bool localUserIsIn = joinState == JoinState::Join; const bool emptyRoom = membersMap.isEmpty() - || (membersMap.size() == 1 && isLocalUser(*membersMap.begin())); + || (membersMap.size() == 1 && isLocalUser(*membersMap.cbegin())); const bool nonEmptySummary = summary.heroes && !summary.heroes->empty(); auto shortlist = nonEmptySummary ? buildShortlist(*summary.heroes) : !emptyRoom ? buildShortlist(membersMap) |