From 2a5301b5a50c49b480b2c3968b4bca2610a8d6f0 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 26 Feb 2017 19:31:48 +0900 Subject: Parse event id for all events; timestamp for all except typing and receipts This is not quite correct because only room events are guaranteed by the spec to have an id and a timestamp. But we don't parse all room events as of yet, so that's a way to at least make those attributes universally available for even unknown room events. It matters, because read receipts can refer to any room event id and because we'll use event id's to filter out duplicate events in further commits; and missing timestamps used to break the timeline display (showing <> instead of ). --- events/event.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'events') diff --git a/events/event.cpp b/events/event.cpp index 43604b23..11983f53 100644 --- a/events/event.cpp +++ b/events/event.cpp @@ -114,31 +114,31 @@ Event* Event::fromJson(const QJsonObject& obj) bool Event::parseJson(const QJsonObject& obj) { d->originalJson = QString::fromUtf8(QJsonDocument(obj).toJson()); + d->id = obj.value("event_id").toString(); + d->roomId = obj.value("room_id").toString(); + d->senderId = obj.value("sender").toString(); bool correct = (d->type != EventType::Unknown); - if ( d->type != EventType::Unknown && - d->type != EventType::Typing && + if ( d->type != EventType::Typing && d->type != EventType::Receipt ) { - if( obj.contains("event_id") ) + if (d->id.isEmpty()) { - d->id = obj.value("event_id").toString(); - } else { correct = false; - qDebug() << "Event: can't find event_id"; + qDebug() << "Event: can't find event_id; event dump follows"; qDebug() << formatJson << obj; } if( obj.contains("origin_server_ts") ) { - d->timestamp = QDateTime::fromMSecsSinceEpoch( + d->timestamp = QDateTime::fromMSecsSinceEpoch( static_cast(obj.value("origin_server_ts").toDouble()), Qt::UTC ); - } else { + } + else if (d->type != EventType::Unknown) + { correct = false; - qDebug() << "Event: can't find ts"; + qDebug() << "Event: can't find ts; event dump follows"; qDebug() << formatJson << obj; } } - d->roomId = obj.value("room_id").toString(); - d->senderId = obj.value("sender").toString(); return correct; } -- cgit v1.2.3