From f7a2e0f9885ecc622c67dd457993cb19c293f515 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sun, 1 Aug 2021 17:17:41 +0200 Subject: 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. --- lib/room.cpp | 14 ++++++++++++-- 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) -- cgit v1.2.3