aboutsummaryrefslogtreecommitdiff
path: root/events
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2017-02-26 19:31:48 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2017-02-28 12:31:37 +0900
commit2a5301b5a50c49b480b2c3968b4bca2610a8d6f0 (patch)
treebdbe39ab981e686cc57ee0dfdc17c81b38e846a6 /events
parent988630bee00d54d64038c8216c64117e9ee02c61 (diff)
downloadlibquotient-2a5301b5a50c49b480b2c3968b4bca2610a8d6f0.tar.gz
libquotient-2a5301b5a50c49b480b2c3968b4bca2610a8d6f0.zip
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 <valid timestamps>).
Diffstat (limited to 'events')
-rw-r--r--events/event.cpp22
1 files changed, 11 insertions, 11 deletions
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<qint64>(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;
}