diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-07-26 08:19:29 +0200 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-07-28 15:08:31 +0200 |
commit | eed5a6f127ec3bb1553ac629457f196d8893665a (patch) | |
tree | 215ae5fae5078494770af36998747fc806963ac2 /lib/room.cpp | |
parent | 000b57306afe450c21df3aa95313567614c34516 (diff) | |
download | libquotient-eed5a6f127ec3bb1553ac629457f196d8893665a.tar.gz libquotient-eed5a6f127ec3bb1553ac629457f196d8893665a.zip |
Room::usersAtEventId(): switch from QMultiHash to QHash of QSets
While slightly more complex for updating, this allows COW to kick in in
the read accessor; using QSet instead of QList also provides better
consistency guarantees. For QML both are converted to an Array-like
collection since Qt 5.15; Qt 5.12 turns QSet<> in a QVariantList,
according to the documentation, which is quite reasonable too.
Diffstat (limited to 'lib/room.cpp')
-rw-r--r-- | lib/room.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/room.cpp b/lib/room.cpp index 10e827d7..13589ee9 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -121,7 +121,7 @@ public: int notificationCount = 0; members_map_t membersMap; QList<User*> usersTyping; - QMultiHash<QString, User*> eventIdReadUsers; + QHash<QString, QSet<User*>> eventIdReadUsers; QList<User*> usersInvited; QList<User*> membersLeft; int unreadMessages = 0; @@ -627,8 +627,11 @@ Room::Changes Room::Private::setLastReadEvent(User* u, QString eventId) auto& storedId = lastReadEventIds[u]; if (storedId == eventId) return Change::NoChange; - eventIdReadUsers.remove(storedId, u); - eventIdReadUsers.insert(eventId, u); + auto& oldEventReadUsers = eventIdReadUsers[storedId]; + oldEventReadUsers.remove(u); + if (oldEventReadUsers.isEmpty()) + eventIdReadUsers.remove(storedId); + eventIdReadUsers[eventId].insert(u); swap(storedId, eventId); emit q->lastReadEventChanged(u); emit q->readMarkerForUserMoved(u, eventId, storedId); @@ -965,9 +968,9 @@ QString Room::readMarkerEventId() const return d->lastReadEventIds.value(localUser()); } -QList<User*> Room::usersAtEventId(const QString& eventId) +QSet<User*> Room::usersAtEventId(const QString& eventId) { - return d->eventIdReadUsers.values(eventId); + return d->eventIdReadUsers.value(eventId); } int Room::notificationCount() const { return d->notificationCount; } |