aboutsummaryrefslogtreecommitdiff
path: root/lib/syncdata.cpp
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-07-24 20:56:50 +0200
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-07-24 20:56:50 +0200
commitcddf3c6a2ab7481e5816ca7632b9f919efa0ac40 (patch)
tree036840ccd377d58717c2a6552652708c91d293b1 /lib/syncdata.cpp
parentf340d73ae5dac0d0cfee732aabbd5222c7be16dd (diff)
downloadlibquotient-cddf3c6a2ab7481e5816ca7632b9f919efa0ac40.tar.gz
libquotient-cddf3c6a2ab7481e5816ca7632b9f919efa0ac40.zip
Wrap SyncRoomData counters into Omittables
Also: introduce a merge(T1&, const Omittable<T2>&) that does pretty much the same as Omittable<T1>::merge(const Omittable<T2>&) except it works on non-omittables as the left/first operand. The change removes the need for a clumsy -2 fallback in unreadCount, and makes the logic loading those counters cleaner along the way.
Diffstat (limited to 'lib/syncdata.cpp')
-rw-r--r--lib/syncdata.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/syncdata.cpp b/lib/syncdata.cpp
index 232f3694..d3c270b5 100644
--- a/lib/syncdata.cpp
+++ b/lib/syncdata.cpp
@@ -90,13 +90,13 @@ 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)
+ fromJson(unreadJson.value(UnreadCountKey), unreadCount);
+ fromJson(unreadJson.value("highlight_count"_ls), highlightCount);
+ fromJson(unreadJson.value("notification_count"_ls), notificationCount);
+ if (highlightCount.has_value() || notificationCount.has_value())
qCDebug(SYNCJOB) << "Room" << roomId_
- << "has highlights:" << highlightCount
- << "and notifications:" << notificationCount;
+ << "has highlights:" << *highlightCount
+ << "and notifications:" << *notificationCount;
}
SyncData::SyncData(const QString& cacheFileName)