diff options
Diffstat (limited to 'events')
-rw-r--r-- | events/event.cpp | 14 | ||||
-rw-r--r-- | events/event.h | 4 |
2 files changed, 16 insertions, 2 deletions
diff --git a/events/event.cpp b/events/event.cpp index c3e94ce1..9a48108c 100644 --- a/events/event.cpp +++ b/events/event.cpp @@ -18,7 +18,7 @@ #include "event.h" -#include <QtCore/QJsonObject> +#include <QtCore/QJsonArray> #include <QtCore/QJsonDocument> #include <QtCore/QDateTime> #include <QtCore/QDebug> @@ -134,7 +134,8 @@ bool Event::parseJson(const QJsonObject& obj) } if( obj.contains("origin_server_ts") ) { - d->timestamp = QDateTime::fromMSecsSinceEpoch( (quint64) obj.value("origin_server_ts").toDouble(), Qt::UTC ); + d->timestamp = QDateTime::fromMSecsSinceEpoch( + static_cast<qint64>(obj.value("origin_server_ts").toDouble()), Qt::UTC ); } else { correct = false; qDebug() << "Event: can't find ts"; @@ -146,3 +147,12 @@ bool Event::parseJson(const QJsonObject& obj) } return correct; } + +QList<Event*> QMatrixClient::eventListFromJson(const QJsonArray& json) +{ + QList<Event*> l; + l.reserve(json.size()); + for (auto event: json) + l.push_back(Event::fromJson(event.toObject())); + return l; +} diff --git a/events/event.h b/events/event.h index 6a8d0e89..a009aa99 100644 --- a/events/event.h +++ b/events/event.h @@ -25,6 +25,8 @@ #include <QtCore/QDateTime> #include <QtCore/QJsonObject> +class QJsonArray; + namespace QMatrixClient { enum class EventType @@ -56,6 +58,8 @@ namespace QMatrixClient Private* d; }; + QList<Event*> eventListFromJson(const QJsonArray& contents); + /** * Finds a place in the timeline where a new event/message could be inserted. * @return an iterator to an item with the earliest timestamp after |