aboutsummaryrefslogtreecommitdiff
path: root/lib/syncdata.cpp
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-11-24 19:39:16 +0100
committerGitHub <noreply@github.com>2021-11-24 19:39:16 +0100
commit91c1d93d3389ac924f1013dc7b37dfe70a17e57e (patch)
treea3cbbccf1cb77e0ced68f5dc1175dde0f8999bb6 /lib/syncdata.cpp
parenta2cc707107464fd98fc8a33afde3ed29f8cd9526 (diff)
parentc57d6de40fb790a4920a9c8ff235511860d68f32 (diff)
downloadlibquotient-91c1d93d3389ac924f1013dc7b37dfe70a17e57e.tar.gz
libquotient-91c1d93d3389ac924f1013dc7b37dfe70a17e57e.zip
Merge pull request #521 from quotient-im/kitsune-unread-statistics
Diffstat (limited to 'lib/syncdata.cpp')
-rw-r--r--lib/syncdata.cpp44
1 files changed, 22 insertions, 22 deletions
diff --git a/lib/syncdata.cpp b/lib/syncdata.cpp
index e86d3100..396e77eb 100644
--- a/lib/syncdata.cpp
+++ b/lib/syncdata.cpp
@@ -10,9 +10,6 @@
using namespace Quotient;
-const QString SyncRoomData::UnreadCountKey =
- QStringLiteral("x-quotient.unread_count");
-
bool RoomSummary::isEmpty() const
{
return !joinedMemberCount && !invitedMemberCount && !heroes;
@@ -64,23 +61,23 @@ inline EventsArrayT load(const QJsonObject& batches, StrT keyName)
return fromJson<EventsArrayT>(batches[keyName].toObject().value("events"_ls));
}
-SyncRoomData::SyncRoomData(const QString& roomId_, JoinState joinState_,
- const QJsonObject& room_)
- : roomId(roomId_)
- , joinState(joinState_)
- , summary(fromJson<RoomSummary>(room_["summary"_ls]))
- , state(load<StateEvents>(room_, joinState == JoinState::Invite
+SyncRoomData::SyncRoomData(QString roomId_, JoinState joinState,
+ const QJsonObject& roomJson)
+ : roomId(std::move(roomId_))
+ , joinState(joinState)
+ , summary(fromJson<RoomSummary>(roomJson["summary"_ls]))
+ , state(load<StateEvents>(roomJson, joinState == JoinState::Invite
? "invite_state"_ls
: "state"_ls))
{
switch (joinState) {
case JoinState::Join:
- ephemeral = load<Events>(room_, "ephemeral"_ls);
+ ephemeral = load<Events>(roomJson, "ephemeral"_ls);
[[fallthrough]];
case JoinState::Leave: {
- accountData = load<Events>(room_, "account_data"_ls);
- timeline = load<RoomEvents>(room_, "timeline"_ls);
- const auto timelineJson = room_.value("timeline"_ls).toObject();
+ accountData = load<Events>(roomJson, "account_data"_ls);
+ timeline = load<RoomEvents>(roomJson, "timeline"_ls);
+ const auto timelineJson = roomJson.value("timeline"_ls).toObject();
timelineLimited = timelineJson.value("limited"_ls).toBool();
timelinePrevBatch = timelineJson.value("prev_batch"_ls).toString();
@@ -89,14 +86,17 @@ SyncRoomData::SyncRoomData(const QString& roomId_, JoinState joinState_,
default: /* nothing on top of state */;
}
- const auto unreadJson = room_.value("unread_notifications"_ls).toObject();
- 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;
+ const auto unreadJson = roomJson.value(UnreadNotificationsKey).toObject();
+
+ fromJson(unreadJson.value(PartiallyReadCountKey), partiallyReadCount);
+ if (!partiallyReadCount.has_value())
+ fromJson(unreadJson.value("x-quotient.unread_count"_ls),
+ partiallyReadCount);
+
+ fromJson(roomJson.value(NewUnreadCountKey), unreadCount);
+ if (!unreadCount.has_value())
+ fromJson(unreadJson.value("notification_count"_ls), unreadCount);
+ fromJson(unreadJson.value(HighlightCountKey), highlightCount);
}
SyncData::SyncData(const QString& cacheFileName)
@@ -130,7 +130,7 @@ Events&& SyncData::takeToDeviceEvents() { return std::move(toDeviceEvents); }
std::pair<int, int> SyncData::cacheVersion()
{
- return { MajorCacheVersion, 1 };
+ return { MajorCacheVersion, 2 };
}
QJsonObject SyncData::loadJson(const QString& fileName)