diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-09-21 20:44:45 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-09-21 20:44:45 +0900 |
commit | 9cc3f82026c64862bae6a535d2b883b8cf97fba0 (patch) | |
tree | 8d2cb44133edc2237278025e2260f88595fa9971 /jobs/syncjob.cpp | |
parent | 16fd53ff0be54531661e9e0cd27c4f893295b62e (diff) | |
parent | f936182135d166e5dea734775e24cabd4b763c64 (diff) | |
download | libquotient-9cc3f82026c64862bae6a535d2b883b8cf97fba0.tar.gz libquotient-9cc3f82026c64862bae6a535d2b883b8cf97fba0.zip |
Merge branch 'master' into kitsune-invite-kick
Diffstat (limited to 'jobs/syncjob.cpp')
-rw-r--r-- | jobs/syncjob.cpp | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/jobs/syncjob.cpp b/jobs/syncjob.cpp index 38cfcb2a..f679e6f4 100644 --- a/jobs/syncjob.cpp +++ b/jobs/syncjob.cpp @@ -22,20 +22,12 @@ 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) { setLoggingCategory(SYNCJOB); QUrlQuery query; @@ -52,47 +44,48 @@ SyncJob::SyncJob(const ConnectionData* connection, const QString& since, setMaxRetries(std::numeric_limits<int>::max()); } -SyncJob::~SyncJob() +QString SyncData::nextBatch() const { - delete d; + return nextBatch_; } -QString SyncJob::nextBatch() const +SyncDataList&& SyncData::takeRoomData() { - return d->nextBatch; + return std::move(roomData); } -SyncData&& SyncJob::takeRoomData() +BaseJob::Status SyncJob::parseJson(const QJsonDocument& data) { - return std::move(d->roomData); + return d.parseJson(data); } -BaseJob::Status SyncJob::parseJson(const QJsonDocument& data) +BaseJob::Status 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(); - 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 - d->roomData.reserve(static_cast<size_t>(rs.size())); - for( auto rkey: rs.keys() ) - d->roomData.emplace_back(rkey, roomState.enumVal, rs[rkey].toObject()); + roomData.reserve(static_cast<size_t>(rs.size())); + for(auto roomIt = rs.begin(); roomIt != rs.end(); ++roomIt) + roomData.emplace_back(roomIt.key(), roomState.enumVal, + roomIt.value().toObject()); } - qCDebug(PROFILER) << "*** SyncJob::parseJson():" << et.elapsed() << "ms"; - - return Success; + qCDebug(PROFILER) << "*** SyncData::parseJson():" << et.elapsed() << "ms"; + return BaseJob::Success; } SyncRoomData::SyncRoomData(const QString& roomId_, JoinState joinState_, |