diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-08-01 17:17:41 +0200 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-08-01 17:17:41 +0200 |
commit | f7a2e0f9885ecc622c67dd457993cb19c293f515 (patch) | |
tree | 4cdf6b1c97310f65b0706eaefd927f8bc0e7f751 /lib | |
parent | 8398e7118503d51da431ba850812ec76d1976b67 (diff) | |
download | libquotient-f7a2e0f9885ecc622c67dd457993cb19c293f515.tar.gz libquotient-f7a2e0f9885ecc622c67dd457993cb19c293f515.zip |
SyncRoomData: distinguish between omitted and 0 unread counters
This is a more conservative but less idiomatic.readable fix for entirely
missing notification_count/highlight_count. In reality, Synapse seems
to always send them; but that is not required by The Spec.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/room.cpp | 14 | ||||
-rw-r--r-- | lib/syncdata.cpp | 8 |
2 files changed, 14 insertions, 8 deletions
diff --git a/lib/room.cpp b/lib/room.cpp index b461b0a1..77abf04c 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -1561,11 +1561,21 @@ void Room::updateData(SyncRoomData&& data, bool fromCache) emit unreadMessagesChanged(this); } - if (data.highlightCount != d->highlightCount) { + // Similar to unreadCount, SyncRoomData constructor assigns -1 to + // highlightCount/notificationCount when those are missing in the payload + if (data.highlightCount != -1 && data.highlightCount != d->highlightCount) { + qCDebug(MESSAGES).nospace() + << "Highlights in " << objectName() // + << ": " << d->highlightCount << " -> " << data.highlightCount; d->highlightCount = data.highlightCount; emit highlightCountChanged(); } - if (data.notificationCount != d->notificationCount) { + if (data.notificationCount != -1 + && data.notificationCount != d->notificationCount) // + { + qCDebug(MESSAGES).nospace() + << "Notifications in " << objectName() // + << ": " << d->notificationCount << " -> " << data.notificationCount; d->notificationCount = data.notificationCount; emit notificationCountChanged(); } diff --git a/lib/syncdata.cpp b/lib/syncdata.cpp index 64aa65fd..70c4a15f 100644 --- a/lib/syncdata.cpp +++ b/lib/syncdata.cpp @@ -106,12 +106,8 @@ SyncRoomData::SyncRoomData(const QString& roomId_, JoinState joinState_, const auto unreadJson = room_.value("unread_notifications"_ls).toObject(); unreadCount = unreadJson.value(UnreadCountKey).toInt(-2); - highlightCount = unreadJson.value("highlight_count"_ls).toInt(); - notificationCount = unreadJson.value("notification_count"_ls).toInt(); - if (highlightCount > 0 || notificationCount > 0) - qCDebug(SYNCJOB) << "Room" << roomId_ - << "has highlights:" << highlightCount - << "and notifications:" << notificationCount; + highlightCount = unreadJson.value("highlight_count"_ls).toInt(-1); + notificationCount = unreadJson.value("notification_count"_ls).toInt(-1); } SyncData::SyncData(const QString& cacheFileName) |