From 1b11a6ee708291db37b0c7879eb103d81d70a6b7 Mon Sep 17 00:00:00 2001
From: Kitsune Ral <Kitsune-Ral@users.sf.net>
Date: Tue, 19 Sep 2017 10:10:18 +0900
Subject: Event::originalJsonObject(), RoomEvent validations commented out

* Event::originalJsonObject() exposes the original JSON for the event without converting it to QByteArray. This is useful to quickly dump an event into a bigger JSON without reconstructing a JSON object.
* Validations in RoomEvent::RoomEvent() do more harm than good. The rest of the library tolerates absence of those attributes pretty well (it wouldn't be able to do much with that anyway); at the same time, dumping JSON to logs turns out to be pretty heavy, and throwing many invalid events at a client is a good way to hit its performance.
---
 events/event.cpp | 35 ++++++++++++++++++++---------------
 events/event.h   |  1 +
 2 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/events/event.cpp b/events/event.cpp
index 8a6de822..d718306d 100644
--- a/events/event.cpp
+++ b/events/event.cpp
@@ -48,6 +48,11 @@ QByteArray Event::originalJson() const
     return QJsonDocument(_originalJson).toJson();
 }
 
+QJsonObject Event::originalJsonObject() const
+{
+    return _originalJson;
+}
+
 QDateTime Event::toTimestamp(const QJsonValue& v)
 {
     Q_ASSERT(v.isDouble() || v.isNull() || v.isUndefined());
@@ -97,21 +102,21 @@ RoomEvent::RoomEvent(Type type, const QJsonObject& rep)
     , _senderId(rep["sender"].toString())
     , _txnId(rep["unsigned"].toObject().value("transactionId").toString())
 {
-    if (_id.isEmpty())
-    {
-        qCWarning(EVENTS) << "Can't find event_id in a room event";
-        qCWarning(EVENTS) << formatJson << rep;
-    }
-    if (!rep.contains("origin_server_ts"))
-    {
-        qCWarning(EVENTS) << "Can't find server timestamp in a room event";
-        qCWarning(EVENTS) << formatJson << rep;
-    }
-    if (_senderId.isEmpty())
-    {
-        qCWarning(EVENTS) << "Can't find sender in a room event";
-        qCWarning(EVENTS) << formatJson << rep;
-    }
+//    if (_id.isEmpty())
+//    {
+//        qCWarning(EVENTS) << "Can't find event_id in a room event";
+//        qCWarning(EVENTS) << formatJson << rep;
+//    }
+//    if (!rep.contains("origin_server_ts"))
+//    {
+//        qCWarning(EVENTS) << "Can't find server timestamp in a room event";
+//        qCWarning(EVENTS) << formatJson << rep;
+//    }
+//    if (_senderId.isEmpty())
+//    {
+//        qCWarning(EVENTS) << "Can't find sender in a room event";
+//        qCWarning(EVENTS) << formatJson << rep;
+//    }
     if (!_txnId.isEmpty())
         qCDebug(EVENTS) << "Event transactionId:" << _txnId;
 }
diff --git a/events/event.h b/events/event.h
index 8760aa28..7db14100 100644
--- a/events/event.h
+++ b/events/event.h
@@ -43,6 +43,7 @@ namespace QMatrixClient
 
             Type type() const { return _type; }
             QByteArray originalJson() const;
+            QJsonObject originalJsonObject() const;
 
             // According to the CS API spec, every event also has
             // a "content" object; but since its structure is different for
-- 
cgit v1.2.3