aboutsummaryrefslogtreecommitdiff
path: root/jobs
diff options
context:
space:
mode:
Diffstat (limited to 'jobs')
-rw-r--r--jobs/syncjob.cpp11
-rw-r--r--jobs/syncjob.h36
2 files changed, 27 insertions, 20 deletions
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;
};