aboutsummaryrefslogtreecommitdiff
path: root/jobs/syncjob.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-03-27 20:34:46 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-03-27 20:34:46 +0900
commitf213e02daa6b9e83e8e76d1576e446357c6c3bc7 (patch)
treeb5b648115723ed9a60d6f6ddef095c7900484e84 /jobs/syncjob.cpp
parentd38020752c4a03fdc5b74f9704b28b302ec5ebf8 (diff)
downloadlibquotient-f213e02daa6b9e83e8e76d1576e446357c6c3bc7.tar.gz
libquotient-f213e02daa6b9e83e8e76d1576e446357c6c3bc7.zip
Rework unread messages counting logic
The previous one didn't cover all the cases; the current one seems to do. Closes #192. Accompanied by the developer's notes at: https://github.com/QMatrixClient/libqmatrixclient/wiki/unread_count
Diffstat (limited to 'jobs/syncjob.cpp')
-rw-r--r--jobs/syncjob.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/jobs/syncjob.cpp b/jobs/syncjob.cpp
index ed579f12..435dfd0e 100644
--- a/jobs/syncjob.cpp
+++ b/jobs/syncjob.cpp
@@ -89,6 +89,9 @@ BaseJob::Status SyncData::parseJson(const QJsonDocument &data)
return BaseJob::Success;
}
+const QString SyncRoomData::UnreadCountKey =
+ QStringLiteral("x-qmatrixclient.unread_count");
+
SyncRoomData::SyncRoomData(const QString& roomId_, JoinState joinState_,
const QJsonObject& room_)
: roomId(roomId_)
@@ -116,12 +119,15 @@ SyncRoomData::SyncRoomData(const QString& roomId_, JoinState joinState_,
qCWarning(SYNCJOB) << "SyncRoomData: Unknown JoinState value, ignoring:" << int(joinState);
}
- QJsonObject timeline = room_.value("timeline").toObject();
- timelineLimited = timeline.value("limited").toBool();
- timelinePrevBatch = timeline.value("prev_batch").toString();
-
- QJsonObject unread = room_.value("unread_notifications").toObject();
- highlightCount = unread.value("highlight_count").toInt();
- notificationCount = unread.value("notification_count").toInt();
- qCDebug(SYNCJOB) << "Highlights: " << highlightCount << " Notifications:" << notificationCount;
+ auto timelineJson = room_.value("timeline").toObject();
+ timelineLimited = timelineJson.value("limited").toBool();
+ timelinePrevBatch = timelineJson.value("prev_batch").toString();
+
+ auto unreadJson = room_.value("unread_notifications").toObject();
+ unreadCount = unreadJson.value(UnreadCountKey).toInt(-2);
+ highlightCount = unreadJson.value("highlight_count").toInt();
+ notificationCount = unreadJson.value("notification_count").toInt();
+ if (highlightCount > 0 || notificationCount > 0)
+ qCDebug(SYNCJOB) << "Highlights: " << highlightCount
+ << " Notifications:" << notificationCount;
}