From 6ae8e3d78b5c4a75ca7d5ca88af730071047d148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Pla=CC=81s=CC=8Cil?= Date: Wed, 16 Aug 2017 13:56:13 +0800 Subject: Implement saving save to enable incremental sync even after shutdown --- jobs/syncjob.cpp | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'jobs/syncjob.cpp') diff --git a/jobs/syncjob.cpp b/jobs/syncjob.cpp index 29ddc2e6..3adf6b0c 100644 --- a/jobs/syncjob.cpp +++ b/jobs/syncjob.cpp @@ -22,20 +22,13 @@ using namespace QMatrixClient; -class SyncJob::Private -{ - public: - QString nextBatch; - SyncData roomData; -}; - static size_t jobId = 0; SyncJob::SyncJob(const ConnectionData* connection, const QString& since, const QString& filter, int timeout, const QString& presence) : BaseJob(connection, HttpVerb::Get, QString("SyncJob-%1").arg(++jobId), "_matrix/client/r0/sync") - , d(new Private) + , d(new SyncData) { setLoggingCategory(SYNCJOB); QUrlQuery query; @@ -57,21 +50,26 @@ SyncJob::~SyncJob() delete d; } -QString SyncJob::nextBatch() const +QString SyncData::nextBatch() const { - return d->nextBatch; + return nextBatch_; } -SyncData&& SyncJob::takeRoomData() +SyncDataList&& SyncData::takeRoomData() { - return std::move(d->roomData); + return std::move(roomData); } BaseJob::Status SyncJob::parseJson(const QJsonDocument& data) { + d->parseJson(data); + return Success; +} + +void SyncData::parseJson(const QJsonDocument &data) { QElapsedTimer et; et.start(); QJsonObject json = data.object(); - d->nextBatch = json.value("next_batch").toString(); + nextBatch_ = json.value("next_batch").toString(); // TODO: presence // TODO: account_data QJsonObject rooms = json.value("rooms").toObject(); @@ -86,13 +84,11 @@ BaseJob::Status SyncJob::parseJson(const QJsonDocument& data) { const QJsonObject rs = rooms.value(roomState.jsonKey).toObject(); // We have a Qt container on the right and an STL one on the left - d->roomData.reserve(static_cast(rs.size())); + roomData.reserve(static_cast(rs.size())); for( auto rkey: rs.keys() ) - d->roomData.emplace_back(rkey, roomState.enumVal, rs[rkey].toObject()); + roomData.emplace_back(rkey, roomState.enumVal, rs[rkey].toObject()); } - qCDebug(PROFILER) << "*** SyncJob::parseJson():" << et.elapsed() << "ms"; - - return Success; + qCDebug(PROFILER) << "*** SyncData::parseJson():" << et.elapsed() << "ms"; } SyncRoomData::SyncRoomData(const QString& roomId_, JoinState joinState_, -- cgit v1.2.3 From 9a26c52f8c3e71f803fd38128ecddfd6ce9748f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Pl=C3=A1=C5=A1il?= Date: Sat, 2 Sep 2017 00:58:58 +0800 Subject: Use status return type for parseJson --- jobs/syncjob.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'jobs/syncjob.cpp') diff --git a/jobs/syncjob.cpp b/jobs/syncjob.cpp index 3adf6b0c..1e71e215 100644 --- a/jobs/syncjob.cpp +++ b/jobs/syncjob.cpp @@ -66,7 +66,7 @@ BaseJob::Status SyncJob::parseJson(const QJsonDocument& data) return Success; } -void SyncData::parseJson(const QJsonDocument &data) { +BaseJob::Status SyncData::parseJson(const QJsonDocument &data) { QElapsedTimer et; et.start(); QJsonObject json = data.object(); nextBatch_ = json.value("next_batch").toString(); @@ -89,6 +89,7 @@ void SyncData::parseJson(const QJsonDocument &data) { roomData.emplace_back(rkey, roomState.enumVal, rs[rkey].toObject()); } qCDebug(PROFILER) << "*** SyncData::parseJson():" << et.elapsed() << "ms"; + return Success; } SyncRoomData::SyncRoomData(const QString& roomId_, JoinState joinState_, -- cgit v1.2.3 From a7ee0dfacc2c571572240191b3cf0846a9e32998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Pla=CC=81s=CC=8Cil?= Date: Sun, 3 Sep 2017 14:43:05 +0800 Subject: More fixes --- jobs/syncjob.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'jobs/syncjob.cpp') diff --git a/jobs/syncjob.cpp b/jobs/syncjob.cpp index 1e71e215..bbec968e 100644 --- a/jobs/syncjob.cpp +++ b/jobs/syncjob.cpp @@ -62,8 +62,7 @@ SyncDataList&& SyncData::takeRoomData() BaseJob::Status SyncJob::parseJson(const QJsonDocument& data) { - d->parseJson(data); - return Success; + return d->parseJson(data); } BaseJob::Status SyncData::parseJson(const QJsonDocument &data) { @@ -89,7 +88,7 @@ BaseJob::Status SyncData::parseJson(const QJsonDocument &data) { roomData.emplace_back(rkey, roomState.enumVal, rs[rkey].toObject()); } qCDebug(PROFILER) << "*** SyncData::parseJson():" << et.elapsed() << "ms"; - return Success; + return BaseJob::Success; } SyncRoomData::SyncRoomData(const QString& roomId_, JoinState joinState_, -- cgit v1.2.3 From 56d34ecab5eb35c426a6e64b034bf2507761dd09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Pla=CC=81s=CC=8Cil?= Date: Mon, 4 Sep 2017 10:35:45 +0800 Subject: Use SyncJob::SyncData as a plain member --- jobs/syncjob.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'jobs/syncjob.cpp') diff --git a/jobs/syncjob.cpp b/jobs/syncjob.cpp index bbec968e..062f1b15 100644 --- a/jobs/syncjob.cpp +++ b/jobs/syncjob.cpp @@ -28,7 +28,6 @@ SyncJob::SyncJob(const ConnectionData* connection, const QString& since, const QString& filter, int timeout, const QString& presence) : BaseJob(connection, HttpVerb::Get, QString("SyncJob-%1").arg(++jobId), "_matrix/client/r0/sync") - , d(new SyncData) { setLoggingCategory(SYNCJOB); QUrlQuery query; @@ -45,11 +44,6 @@ SyncJob::SyncJob(const ConnectionData* connection, const QString& since, setMaxRetries(std::numeric_limits::max()); } -SyncJob::~SyncJob() -{ - delete d; -} - QString SyncData::nextBatch() const { return nextBatch_; @@ -62,7 +56,7 @@ SyncDataList&& SyncData::takeRoomData() BaseJob::Status SyncJob::parseJson(const QJsonDocument& data) { - return d->parseJson(data); + return d.parseJson(data); } BaseJob::Status SyncData::parseJson(const QJsonDocument &data) { -- cgit v1.2.3 From 24e3d967d7c9029147202e10385b0b8e8881e4d9 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 9 Sep 2017 20:17:42 +0900 Subject: Kicking, inviting, exposing rooms in Invite state Kicking and inviting use generated job classes. Rooms in Invite state are stored separately in the hash from those in Join/Leave state because The Spec says so. For clients, this means that the same room may appear twice in the rooms map if it's been left and then the user was again invited to it. The code in Quaternion that properly processes this will arrive shortly. --- jobs/syncjob.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'jobs/syncjob.cpp') diff --git a/jobs/syncjob.cpp b/jobs/syncjob.cpp index 29ddc2e6..38cfcb2a 100644 --- a/jobs/syncjob.cpp +++ b/jobs/syncjob.cpp @@ -99,15 +99,14 @@ SyncRoomData::SyncRoomData(const QString& roomId_, JoinState joinState_, const QJsonObject& room_) : roomId(roomId_) , joinState(joinState_) - , state("state") + , state(joinState == JoinState::Invite ? "invite_state" : "state") , timeline("timeline") , ephemeral("ephemeral") , accountData("account_data") - , inviteState("invite_state") { switch (joinState) { case JoinState::Invite: - inviteState.fromJson(room_); + state.fromJson(room_); break; case JoinState::Join: state.fromJson(room_); -- cgit v1.2.3 From 7e8c2ee1d00e43aab90030493c31aef0b4467f71 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Wed, 20 Sep 2017 13:00:21 +0900 Subject: Minor optimisations in sync data parsing --- jobs/syncjob.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'jobs/syncjob.cpp') diff --git a/jobs/syncjob.cpp b/jobs/syncjob.cpp index 062f1b15..78a9e93f 100644 --- a/jobs/syncjob.cpp +++ b/jobs/syncjob.cpp @@ -59,27 +59,30 @@ BaseJob::Status SyncJob::parseJson(const QJsonDocument& data) return d.parseJson(data); } -BaseJob::Status SyncData::parseJson(const QJsonDocument &data) { +BaseJob::Status SyncData::parseJson(const QJsonDocument &data) +{ QElapsedTimer et; et.start(); + QJsonObject json = data.object(); nextBatch_ = json.value("next_batch").toString(); // TODO: presence // TODO: account_data QJsonObject rooms = json.value("rooms").toObject(); - const struct { QString jsonKey; JoinState enumVal; } roomStates[] + static const struct { QString jsonKey; JoinState enumVal; } roomStates[] { { "join", JoinState::Join }, { "invite", JoinState::Invite }, { "leave", JoinState::Leave } }; - for (auto roomState: roomStates) + for (const auto& roomState: roomStates) { const QJsonObject rs = rooms.value(roomState.jsonKey).toObject(); // We have a Qt container on the right and an STL one on the left roomData.reserve(static_cast(rs.size())); - for( auto rkey: rs.keys() ) - roomData.emplace_back(rkey, roomState.enumVal, rs[rkey].toObject()); + for(auto roomIt = rs.begin(); roomIt != rs.end(); ++roomIt) + roomData.emplace_back(roomIt.key(), roomState.enumVal, + roomIt.value().toObject()); } qCDebug(PROFILER) << "*** SyncData::parseJson():" << et.elapsed() << "ms"; return BaseJob::Success; -- cgit v1.2.3