aboutsummaryrefslogtreecommitdiff
path: root/lib/events/receiptevent.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-01 22:48:38 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-04 09:07:32 +0900
commitf1ffe1e7a3e81c07a07a8416ce307e4413ec8fbc (patch)
treef2435183d11a4cea52a7532eb9ff3d4d837e1d22 /lib/events/receiptevent.cpp
parentd5397fe5ae2ca34d5cfb11394dac17728a2b50ce (diff)
downloadlibquotient-f1ffe1e7a3e81c07a07a8416ce307e4413ec8fbc.tar.gz
libquotient-f1ffe1e7a3e81c07a07a8416ce307e4413ec8fbc.zip
Event types system remade to be extensible
There were two common points that had to be updated every time a new event is introduced: the EventType enumeration and one of 3 doMakeEvent<> specialisations. The new code has a template class, EventFactory<>, that uses a list of static factory methods to create events instead of typelists used in doMakeEvent<>(); the EventType enumeration is replaced with a namespace populated with constants as necessary. In general, EventType is considered a deprecated mechanism altogether; instead, a set of facilities is provided: is<>() to check if an event has a certain type (to replace comparison against an EventType value) and visit<>() to execute actions based on the event type (replacing switch statements over EventType values). Closes #129.
Diffstat (limited to 'lib/events/receiptevent.cpp')
-rw-r--r--lib/events/receiptevent.cpp12
1 files changed, 5 insertions, 7 deletions
diff --git a/lib/events/receiptevent.cpp b/lib/events/receiptevent.cpp
index a12f4c05..3451a40e 100644
--- a/lib/events/receiptevent.cpp
+++ b/lib/events/receiptevent.cpp
@@ -35,17 +35,14 @@ Example of a Receipt Event:
#include "receiptevent.h"
-#include "converters.h"
#include "logging.h"
using namespace QMatrixClient;
ReceiptEvent::ReceiptEvent(const QJsonObject& obj)
- : Event(Type::Receipt, obj)
+ : Event(typeId(), obj)
{
- Q_ASSERT(obj["type"].toString() == typeId());
-
- const QJsonObject contents = contentJson();
+ const auto& contents = contentJson();
_eventsWithReceipts.reserve(contents.size());
for( auto eventIt = contents.begin(); eventIt != contents.end(); ++eventIt )
{
@@ -55,14 +52,15 @@ ReceiptEvent::ReceiptEvent(const QJsonObject& obj)
qCDebug(EPHEMERAL) << "ReceiptEvent content follows:\n" << contents;
continue;
}
- const QJsonObject reads = eventIt.value().toObject().value("m.read").toObject();
+ const QJsonObject reads = eventIt.value().toObject()
+ .value("m.read"_ls).toObject();
QVector<Receipt> receipts;
receipts.reserve(reads.size());
for( auto userIt = reads.begin(); userIt != reads.end(); ++userIt )
{
const QJsonObject user = userIt.value().toObject();
receipts.push_back({userIt.key(),
- QMatrixClient::fromJson<QDateTime>(user["ts"])});
+ fromJson<QDateTime>(user["ts"_ls])});
}
_eventsWithReceipts.push_back({eventIt.key(), std::move(receipts)});
}