aboutsummaryrefslogtreecommitdiff
path: root/jobs
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2017-05-28 13:00:44 +0900
committerGitHub <noreply@github.com>2017-05-28 13:00:44 +0900
commit36dbba9c543b819aec526f18c33f1d95b0ee61c7 (patch)
tree49caf6450be52072d8f1e4e40e2dfb8490d73732 /jobs
parentced7a66686596e74a1f25b5d9634b9b562870943 (diff)
parenta5e14da86c3299ca8d36eb4a4eb58ce2a245dc4e (diff)
downloadlibquotient-36dbba9c543b819aec526f18c33f1d95b0ee61c7.tar.gz
libquotient-36dbba9c543b819aec526f18c33f1d95b0ee61c7.zip
Merge pull request #65 from QMatrixClient/kitsune-simplify-events
Events refactoring
Diffstat (limited to 'jobs')
-rw-r--r--jobs/passwordlogin.h2
-rw-r--r--jobs/roommessagesjob.cpp9
-rw-r--r--jobs/roommessagesjob.h2
-rw-r--r--jobs/syncjob.cpp6
-rw-r--r--jobs/syncjob.h55
5 files changed, 37 insertions, 37 deletions
diff --git a/jobs/passwordlogin.h b/jobs/passwordlogin.h
index 713a1821..6b7db0b3 100644
--- a/jobs/passwordlogin.h
+++ b/jobs/passwordlogin.h
@@ -40,4 +40,4 @@ namespace QMatrixClient
class Private;
Private* d;
};
-}
+} // namespace QMatrixClient
diff --git a/jobs/roommessagesjob.cpp b/jobs/roommessagesjob.cpp
index a48403c8..3e603a50 100644
--- a/jobs/roommessagesjob.cpp
+++ b/jobs/roommessagesjob.cpp
@@ -17,16 +17,15 @@
*/
#include "roommessagesjob.h"
-#include "../util.h"
-#include <QtCore/QJsonArray>
+#include "util.h"
using namespace QMatrixClient;
class RoomMessagesJob::Private
{
public:
- Owning<Events> events;
+ Owning<RoomEvents> events;
QString end;
};
@@ -49,7 +48,7 @@ RoomMessagesJob::~RoomMessagesJob()
delete d;
}
-Events RoomMessagesJob::releaseEvents()
+RoomEvents RoomMessagesJob::releaseEvents()
{
return d->events.release();
}
@@ -62,7 +61,7 @@ QString RoomMessagesJob::end()
BaseJob::Status RoomMessagesJob::parseJson(const QJsonDocument& data)
{
QJsonObject obj = data.object();
- d->events.assign(eventsFromJson(obj.value("chunk").toArray()));
+ d->events.assign(makeEvents<RoomEvent>(obj.value("chunk").toArray()));
d->end = obj.value("end").toString();
return Success;
}
diff --git a/jobs/roommessagesjob.h b/jobs/roommessagesjob.h
index 2d15d9d4..a029c27c 100644
--- a/jobs/roommessagesjob.h
+++ b/jobs/roommessagesjob.h
@@ -34,7 +34,7 @@ namespace QMatrixClient
FetchDirection dir = FetchDirection::Backward);
virtual ~RoomMessagesJob();
- Events releaseEvents();
+ RoomEvents releaseEvents();
QString end();
protected:
diff --git a/jobs/syncjob.cpp b/jobs/syncjob.cpp
index 5984128f..29ddc2e6 100644
--- a/jobs/syncjob.cpp
+++ b/jobs/syncjob.cpp
@@ -18,7 +18,6 @@
#include "syncjob.h"
-#include <QtCore/QJsonArray>
#include <QtCore/QElapsedTimer>
using namespace QMatrixClient;
@@ -96,11 +95,6 @@ BaseJob::Status SyncJob::parseJson(const QJsonDocument& data)
return Success;
}
-void SyncRoomData::EventList::fromJson(const QJsonObject& roomContents)
-{
- assign(eventsFromJson(roomContents[jsonKey].toObject()["events"].toArray()));
-}
-
SyncRoomData::SyncRoomData(const QString& roomId_, JoinState joinState_,
const QJsonObject& room_)
: roomId(roomId_)
diff --git a/jobs/syncjob.h b/jobs/syncjob.h
index 48be9423..07824e23 100644
--- a/jobs/syncjob.h
+++ b/jobs/syncjob.h
@@ -20,39 +20,46 @@
#include "basejob.h"
-#include "../joinstate.h"
-#include "../events/event.h"
+#include "joinstate.h"
+#include "events/event.h"
#include "util.h"
namespace QMatrixClient
{
class SyncRoomData
{
- public:
- class EventList : public Owning<Events>
- {
- private:
- QString jsonKey;
- public:
- explicit EventList(QString k) : jsonKey(std::move(k)) { }
- void fromJson(const QJsonObject& roomContents);
- };
+ public:
+ template <typename EventT>
+ class Batch : public Owning<EventsBatch<EventT>>
+ {
+ public:
+ explicit Batch(QString k) : jsonKey(std::move(k)) { }
+ void fromJson(const QJsonObject& roomContents)
+ {
+ this->assign(makeEvents<EventT>(
+ roomContents[jsonKey].toObject()["events"].toArray()));
+ }
+
+
+ private:
+ QString jsonKey;
+ };
- QString roomId;
- JoinState joinState;
- EventList state;
- EventList timeline;
- EventList ephemeral;
- EventList accountData;
- EventList inviteState;
+ QString roomId;
+ JoinState joinState;
+ Batch<RoomEvent> state;
+ Batch<RoomEvent> timeline;
+ Batch<Event> ephemeral;
+ Batch<Event> accountData;
+ Batch<Event> inviteState;
- bool timelineLimited;
- QString timelinePrevBatch;
- int highlightCount;
- int notificationCount;
+ bool timelineLimited;
+ QString timelinePrevBatch;
+ int highlightCount;
+ int notificationCount;
- SyncRoomData(const QString& roomId, JoinState joinState_,
- const QJsonObject& room_);
+ SyncRoomData(const QString& roomId, JoinState joinState_,
+ const QJsonObject& room_);
};
} // namespace QMatrixClient
Q_DECLARE_TYPEINFO(QMatrixClient::SyncRoomData, Q_MOVABLE_TYPE);