diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-02-27 19:51:08 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-02-27 19:51:08 +0900 |
commit | 375bea5ee67a90c6419acf50c06c05ed0435c772 (patch) | |
tree | 76f0a1c830797fe1b17b3bea67ddaf7fb53cbd6a /jobs | |
parent | e80bfd2fc710d4780a2c22bde9d605a41bd4aaa4 (diff) | |
parent | efeeca097a3c69991683615366f07625855ba2ac (diff) | |
download | libquotient-375bea5ee67a90c6419acf50c06c05ed0435c772.tar.gz libquotient-375bea5ee67a90c6419acf50c06c05ed0435c772.zip |
Merge branch 'master' into kitsune-gtad
Diffstat (limited to 'jobs')
-rw-r--r-- | jobs/basejob.cpp | 7 | ||||
-rw-r--r-- | jobs/basejob.h | 3 | ||||
-rw-r--r-- | jobs/mediathumbnailjob.cpp | 14 | ||||
-rw-r--r-- | jobs/syncjob.cpp | 11 | ||||
-rw-r--r-- | jobs/syncjob.h | 36 |
5 files changed, 44 insertions, 27 deletions
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp index 0e3e59d0..486956e1 100644 --- a/jobs/basejob.cpp +++ b/jobs/basejob.cpp @@ -266,6 +266,12 @@ void BaseJob::gotReply() setStatus(checkReply(d->reply.data())); if (status().good()) setStatus(parseReply(d->reply.data())); + else + { + auto json = QJsonDocument::fromJson(d->reply->readAll()).object(); + if (!json.isEmpty()) + setStatus(IncorrectRequestError, json.value("error").toString()); + } finishJob(); } @@ -447,6 +453,7 @@ void BaseJob::setStatus(int code, QString message) void BaseJob::abandon() { beforeAbandon(d->reply.data()); + setStatus(Abandoned); this->disconnect(); if (d->reply) d->reply->disconnect(this); diff --git a/jobs/basejob.h b/jobs/basejob.h index c03c914f..a5b457c5 100644 --- a/jobs/basejob.h +++ b/jobs/basejob.h @@ -53,7 +53,8 @@ namespace QMatrixClient enum StatusCode { NoError = 0 // To be compatible with Qt conventions , Success = 0 , Pending = 1 - , ErrorLevel = 100 // Errors have codes starting from this + , Abandoned = 50 //< A very brief period between abandoning and object deletion + , ErrorLevel = 100 //< Errors have codes starting from this , NetworkError = 100 , JsonParseError , TimeoutError diff --git a/jobs/mediathumbnailjob.cpp b/jobs/mediathumbnailjob.cpp index 261978ec..dda1cdb4 100644 --- a/jobs/mediathumbnailjob.cpp +++ b/jobs/mediathumbnailjob.cpp @@ -52,10 +52,12 @@ QImage MediaThumbnailJob::scaledThumbnail(QSize toSize) const BaseJob::Status MediaThumbnailJob::parseReply(QNetworkReply* reply) { - GetContentThumbnailJob::parseReply(reply); - if( !_thumbnail.loadFromData(content()->readAll()) ) - { - qCDebug(JOBS) << "MediaThumbnailJob: could not read image data"; - } - return Success; + auto result = GetContentThumbnailJob::parseReply(reply); + if (!result.good()) + return result; + + if( _thumbnail.loadFromData(content()->readAll()) ) + return Success; + + return { IncorrectResponseError, "Could not read image data" }; } diff --git a/jobs/syncjob.cpp b/jobs/syncjob.cpp index ce5dd894..7b066f4f 100644 --- a/jobs/syncjob.cpp +++ b/jobs/syncjob.cpp @@ -54,6 +54,11 @@ SyncDataList&& SyncData::takeRoomData() return std::move(roomData); } +SyncBatch<Event>&& SyncData::takeAccountData() +{ + return std::move(accountData); +} + BaseJob::Status SyncJob::parseJson(const QJsonDocument& data) { return d.parseJson(data); @@ -63,12 +68,12 @@ BaseJob::Status SyncData::parseJson(const QJsonDocument &data) { QElapsedTimer et; et.start(); - QJsonObject json = data.object(); + auto json { data.object() }; nextBatch_ = json.value("next_batch").toString(); // TODO: presence - // TODO: account_data - QJsonObject rooms = json.value("rooms").toObject(); + accountData.fromJson(json); + QJsonObject rooms = json.value("rooms").toObject(); for (size_t i = 0; i < JoinStateStrings.size(); ++i) { const auto rs = rooms.value(JoinStateStrings[i]).toObject(); diff --git a/jobs/syncjob.h b/jobs/syncjob.h index aed36e0b..5956e73b 100644 --- a/jobs/syncjob.h +++ b/jobs/syncjob.h @@ -26,30 +26,30 @@ namespace QMatrixClient { - class SyncRoomData + template <typename EventT> + class SyncBatch : public EventsBatch<EventT> { public: - template <typename EventT> - class Batch : public EventsBatch<EventT> + explicit SyncBatch(QString k) : jsonKey(std::move(k)) { } + void fromJson(const QJsonObject& roomContents) { - public: - explicit Batch(QString k) : jsonKey(std::move(k)) { } - void fromJson(const QJsonObject& roomContents) - { - EventsBatch<EventT>::fromJson( - roomContents[jsonKey].toObject(), "events"); - } + EventsBatch<EventT>::fromJson( + roomContents[jsonKey].toObject(), "events"); + } - private: - QString jsonKey; - }; + private: + QString jsonKey; + }; + class SyncRoomData + { + public: QString roomId; JoinState joinState; - Batch<RoomEvent> state; - Batch<RoomEvent> timeline; - Batch<Event> ephemeral; - Batch<Event> accountData; + SyncBatch<RoomEvent> state; + SyncBatch<RoomEvent> timeline; + SyncBatch<Event> ephemeral; + SyncBatch<Event> accountData; bool timelineLimited; QString timelinePrevBatch; @@ -68,11 +68,13 @@ namespace QMatrixClient { public: BaseJob::Status parseJson(const QJsonDocument &data); + SyncBatch<Event>&& takeAccountData(); SyncDataList&& takeRoomData(); QString nextBatch() const; private: QString nextBatch_; + SyncBatch<Event> accountData { "account_data" }; SyncDataList roomData; }; |