diff options
-rw-r--r-- | events/event.cpp | 10 | ||||
-rw-r--r-- | events/event.h | 12 | ||||
-rw-r--r-- | jobs/roommessagesjob.cpp | 7 | ||||
-rw-r--r-- | jobs/roommessagesjob.h | 5 | ||||
-rw-r--r-- | jobs/syncjob.cpp | 3 | ||||
-rw-r--r-- | jobs/syncjob.h | 5 |
6 files changed, 24 insertions, 18 deletions
diff --git a/events/event.cpp b/events/event.cpp index 1235780d..11ed1cc9 100644 --- a/events/event.cpp +++ b/events/event.cpp @@ -144,11 +144,11 @@ bool Event::parseJson(const QJsonObject& obj) return correct; } -QList<Event*> QMatrixClient::eventListFromJson(const QJsonArray& json) +Events QMatrixClient::eventsFromJson(const QJsonArray& json) { - QList<Event*> l; - l.reserve(json.size()); + Events evs; + evs.reserve(json.size()); for (auto event: json) - l.push_back(Event::fromJson(event.toObject())); - return l; + evs.push_back(Event::fromJson(event.toObject())); + return evs; } diff --git a/events/event.h b/events/event.h index 72d26208..d9316747 100644 --- a/events/event.h +++ b/events/event.h @@ -24,6 +24,7 @@ #include <QtCore/QString> #include <QtCore/QDateTime> #include <QtCore/QJsonObject> +#include <QtCore/QVector> class QJsonArray; @@ -38,7 +39,8 @@ namespace QMatrixClient class Event { public: - Event(EventType type); + explicit Event(EventType type); + Event(Event&) = delete; virtual ~Event(); EventType type() const; @@ -57,8 +59,9 @@ namespace QMatrixClient class Private; Private* d; }; + using Events = QVector<Event*>; - QList<Event*> eventListFromJson(const QJsonArray& contents); + Events eventsFromJson(const QJsonArray& contents); /** * Finds a place in the timeline where a new event/message could be inserted. @@ -71,6 +74,11 @@ namespace QMatrixClient { return std::lower_bound (timeline.begin(), timeline.end(), item, [](const typename ContT::value_type a, const ItemT * b) { + // FIXME: We should not order the message list by origin timestamp. + // Rather, an order of receiving should be used (which actually + // poses a question on whether this method is needed at all - + // or we'd just prepend and append, depending on whether we + // received something from /sync or from /messages. return a->timestamp() < b->timestamp(); } ); diff --git a/jobs/roommessagesjob.cpp b/jobs/roommessagesjob.cpp index ba075007..f880713d 100644 --- a/jobs/roommessagesjob.cpp +++ b/jobs/roommessagesjob.cpp @@ -18,7 +18,6 @@ #include "roommessagesjob.h" #include "../room.h" -#include "../events/event.h" #include <QtCore/QJsonObject> #include <QtCore/QJsonArray> @@ -35,7 +34,7 @@ class RoomMessagesJob::Private FetchDirectory dir; int limit; - QList<Event*> events; + Events events; QString end; }; @@ -54,7 +53,7 @@ RoomMessagesJob::~RoomMessagesJob() delete d; } -QList<Event*> RoomMessagesJob::events() +Events RoomMessagesJob::events() { return d->events; } @@ -84,7 +83,7 @@ QUrlQuery RoomMessagesJob::query() const BaseJob::Status RoomMessagesJob::parseJson(const QJsonDocument& data) { QJsonObject obj = data.object(); - d->events = eventListFromJson(obj.value("chunk").toArray()); + d->events = eventsFromJson(obj.value("chunk").toArray()); d->end = obj.value("end").toString(); return Success; } diff --git a/jobs/roommessagesjob.h b/jobs/roommessagesjob.h index 52a72f70..9bedcad9 100644 --- a/jobs/roommessagesjob.h +++ b/jobs/roommessagesjob.h @@ -21,10 +21,11 @@ #include "basejob.h" +#include "../events/event.h" + namespace QMatrixClient { class Room; - class Event; enum class FetchDirectory { Backwards, Forward }; @@ -34,7 +35,7 @@ namespace QMatrixClient RoomMessagesJob(ConnectionData* data, Room* room, QString from, FetchDirectory dir = FetchDirectory::Backwards, int limit=10); virtual ~RoomMessagesJob(); - QList<Event*> events(); + Events events(); QString end(); protected: diff --git a/jobs/syncjob.cpp b/jobs/syncjob.cpp index a9865b55..2b2705b1 100644 --- a/jobs/syncjob.cpp +++ b/jobs/syncjob.cpp @@ -26,7 +26,6 @@ #include "../room.h" #include "../connectiondata.h" -#include "../events/event.h" using namespace QMatrixClient; @@ -139,7 +138,7 @@ BaseJob::Status SyncJob::parseJson(const QJsonDocument& data) void SyncRoomData::EventList::fromJson(const QJsonObject& roomContents) { - auto l = eventListFromJson(roomContents[jsonKey].toObject()["events"].toArray()); + auto l = eventsFromJson(roomContents[jsonKey].toObject()["events"].toArray()); swap(l); } diff --git a/jobs/syncjob.h b/jobs/syncjob.h index f08a6b56..ed99b38b 100644 --- a/jobs/syncjob.h +++ b/jobs/syncjob.h @@ -22,15 +22,14 @@ #include "basejob.h" #include "../joinstate.h" +#include "../events/event.h" namespace QMatrixClient { - class Event; - class SyncRoomData { public: - class EventList : public QList<Event*> + class EventList : public Events { private: QString jsonKey; |