diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-11-21 06:03:49 +0100 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-11-21 07:07:00 +0100 |
commit | 96f3daf7a2c4ec875904c11350c93612265e2eed (patch) | |
tree | c53404fd7c888ec5bd14fd51fabe18c8eb1ba8d6 /lib/room.cpp | |
parent | bf5f209d2d237301c65cc0973f1707b9386f3110 (diff) | |
download | libquotient-96f3daf7a2c4ec875904c11350c93612265e2eed.tar.gz libquotient-96f3daf7a2c4ec875904c11350c93612265e2eed.zip |
SyncData: support MSC2654; partiallyReadCount
Since MSC2654's unread count is counted from the m.read receipt, and
the course is to follow the spec's terminology and use "unread count"
for the number of notable events since m.read, this required to move
the existing number of notable events since m.fully_read to another
field, henceforth called partiallyReadCount. At the same time,
SyncData::notificationCount is dropped completely since MSC2654 claims
to supersede it.
Also: Room::resetNotificationCount() and Room::resetHighlightCount() are
deprecated, as these never worked properly overwriting values that can
be calculated or sourced from the server, only for these values to be
set back again the next time the room is updated from /sync.
Diffstat (limited to 'lib/room.cpp')
-rw-r--r-- | lib/room.cpp | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/lib/room.cpp b/lib/room.cpp index 67f65472..bc686962 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -117,7 +117,7 @@ public: QString displayname; Avatar avatar; QHash<QString, Notification> notifications; - int highlightCount = 0; + qsizetype serverHighlightCount = 0; int notificationCount = 0; members_map_t membersMap; QList<User*> usersTyping; @@ -1072,13 +1072,13 @@ void Room::resetNotificationCount() emit notificationCountChanged(); } -int Room::highlightCount() const { return d->highlightCount; } +qsizetype Room::highlightCount() const { return d->serverHighlightCount; } void Room::resetHighlightCount() { - if (d->highlightCount == 0) + if (d->serverHighlightCount == 0) return; - d->highlightCount = 0; + d->serverHighlightCount = 0; emit highlightCountChanged(); } @@ -1673,16 +1673,16 @@ void Room::updateData(SyncRoomData&& data, bool fromCache) roomChanges |= processEphemeralEvent(move(ephemeralEvent)); // See https://github.com/quotient-im/libQuotient/wiki/unread_count - if (merge(d->unreadMessages, data.unreadCount)) { - qCDebug(MESSAGES) << "Loaded unread_count:" << *data.unreadCount // - << "in" << objectName(); + if (merge(d->unreadMessages, data.partiallyReadCount)) { + qCDebug(MESSAGES) << "Loaded partially read count:" + << *data.partiallyReadCount << "in" << objectName(); emit unreadMessagesChanged(this); } - if (merge(d->highlightCount, data.highlightCount)) + if (merge(d->serverHighlightCount, data.highlightCount)) emit highlightCountChanged(); - if (merge(d->notificationCount, data.notificationCount)) + if (merge(d->notificationCount, data.unreadCount)) emit notificationCountChanged(); if (roomChanges) { @@ -3077,16 +3077,15 @@ QJsonObject Room::Private::toJson() const .fullJson() } } }); } - QJsonObject unreadNotifObj { { SyncRoomData::UnreadCountKey, - unreadMessages } }; + QJsonObject unreadNotifObj { { PartiallyReadCountKey, unreadMessages } }; - if (highlightCount > 0) - unreadNotifObj.insert(QStringLiteral("highlight_count"), highlightCount); - if (notificationCount > 0) - unreadNotifObj.insert(QStringLiteral("notification_count"), - notificationCount); + if (serverHighlightCount > 0) + unreadNotifObj.insert(HighlightCountKey, serverHighlightCount); + + result.insert(UnreadNotificationsKey, unreadNotifObj); - result.insert(QStringLiteral("unread_notifications"), unreadNotifObj); + if (notificationCount > 0) + unreadNotifObj.insert(NewUnreadCountKey, notificationCount); if (et.elapsed() > 30) qCDebug(PROFILER) << "Room::toJson() for" << q->objectName() << "took" |