aboutsummaryrefslogtreecommitdiff
path: root/jobs
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2017-05-22 10:22:28 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2017-05-22 10:22:28 +0900
commitbe838b2f4f294a7e1b3f8a771f91d9d1eac14431 (patch)
treef720ae5a5a52bdd48fdaec17dea3c1c32fe10cd9 /jobs
parent34764f3020c360ebc769cfe154e79b9e7e98f0f7 (diff)
downloadlibquotient-be838b2f4f294a7e1b3f8a771f91d9d1eac14431.tar.gz
libquotient-be838b2f4f294a7e1b3f8a771f91d9d1eac14431.zip
Refactored Events
The biggest change is we have no pimpls in Event objects anymore - because it's two new's instead of one per Event, and we have thousands and even more of Events created during initial sync. The other big change is introduction of RoomEvent, so that now the structure of events almost precisely reflects the CS API spec. The refactoring made UnknownEvent unnecessary as a separate class; a respective base class (either RoomEvent or Event) is used for this purpose now. All the other changes are consequences of these (mostly of RoomEvent introduction).
Diffstat (limited to 'jobs')
-rw-r--r--jobs/roommessagesjob.cpp9
-rw-r--r--jobs/roommessagesjob.h2
-rw-r--r--jobs/syncjob.cpp6
-rw-r--r--jobs/syncjob.h55
4 files changed, 36 insertions, 36 deletions
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);