aboutsummaryrefslogtreecommitdiff
path: root/jobs
diff options
context:
space:
mode:
Diffstat (limited to 'jobs')
-rw-r--r--jobs/syncjob.cpp34
-rw-r--r--jobs/syncjob.h20
2 files changed, 26 insertions, 28 deletions
diff --git a/jobs/syncjob.cpp b/jobs/syncjob.cpp
index 29ddc2e6..062f1b15 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,26 +44,25 @@ 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();
@@ -86,13 +77,12 @@ 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<size_t>(rs.size()));
+ roomData.reserve(static_cast<size_t>(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";
+ return BaseJob::Success;
}
SyncRoomData::SyncRoomData(const QString& roomId_, JoinState joinState_,
diff --git a/jobs/syncjob.h b/jobs/syncjob.h
index 07824e23..2ded0df3 100644
--- a/jobs/syncjob.h
+++ b/jobs/syncjob.h
@@ -67,7 +67,18 @@ Q_DECLARE_TYPEINFO(QMatrixClient::SyncRoomData, Q_MOVABLE_TYPE);
namespace QMatrixClient
{
// QVector cannot work with non-copiable objects, std::vector can.
- using SyncData = std::vector<SyncRoomData>;
+ using SyncDataList = std::vector<SyncRoomData>;
+
+ class SyncData {
+ public:
+ BaseJob::Status parseJson(const QJsonDocument &data);
+ SyncDataList&& takeRoomData();
+ QString nextBatch() const;
+
+ private:
+ QString nextBatch_;
+ SyncDataList roomData;
+ };
class SyncJob: public BaseJob
{
@@ -75,16 +86,13 @@ namespace QMatrixClient
explicit SyncJob(const ConnectionData* connection, const QString& since = {},
const QString& filter = {},
int timeout = -1, const QString& presence = {});
- virtual ~SyncJob();
- SyncData&& takeRoomData();
- QString nextBatch() const;
+ SyncData &&takeData() { return std::move(d); }
protected:
Status parseJson(const QJsonDocument& data) override;
private:
- class Private;
- Private* d;
+ SyncData d;
};
} // namespace QMatrixClient