diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-05-28 13:00:44 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-28 13:00:44 +0900 |
commit | 36dbba9c543b819aec526f18c33f1d95b0ee61c7 (patch) | |
tree | 49caf6450be52072d8f1e4e40e2dfb8490d73732 /events/receiptevent.cpp | |
parent | ced7a66686596e74a1f25b5d9634b9b562870943 (diff) | |
parent | a5e14da86c3299ca8d36eb4a4eb58ce2a245dc4e (diff) | |
download | libquotient-36dbba9c543b819aec526f18c33f1d95b0ee61c7.tar.gz libquotient-36dbba9c543b819aec526f18c33f1d95b0ee61c7.zip |
Merge pull request #65 from QMatrixClient/kitsune-simplify-events
Events refactoring
Diffstat (limited to 'events/receiptevent.cpp')
-rw-r--r-- | events/receiptevent.cpp | 40 |
1 files changed, 9 insertions, 31 deletions
diff --git a/events/receiptevent.cpp b/events/receiptevent.cpp index c163424f..e3478cf1 100644 --- a/events/receiptevent.cpp +++ b/events/receiptevent.cpp @@ -41,34 +41,13 @@ Example of a Receipt Event: using namespace QMatrixClient; -class ReceiptEvent::Private +ReceiptEvent::ReceiptEvent(const QJsonObject& obj) + : Event(Type::Receipt, obj) { - public: - EventsToReceipts eventsToReceipts; -}; + Q_ASSERT(obj["type"].toString() == jsonType); -ReceiptEvent::ReceiptEvent() - : Event(EventType::Receipt) - , d(new Private) -{ -} - -ReceiptEvent::~ReceiptEvent() -{ - delete d; -} - -EventsToReceipts ReceiptEvent::events() const -{ - return d->eventsToReceipts; -} - -ReceiptEvent* ReceiptEvent::fromJson(const QJsonObject& obj) -{ - ReceiptEvent* e = new ReceiptEvent(); - e->parseJson(obj); const QJsonObject contents = obj["content"].toObject(); - e->d->eventsToReceipts.reserve(contents.size()); + _eventsWithReceipts.reserve(static_cast<size_t>(contents.size())); for( auto eventIt = contents.begin(); eventIt != contents.end(); ++eventIt ) { if (eventIt.key().isEmpty()) @@ -78,15 +57,14 @@ ReceiptEvent* ReceiptEvent::fromJson(const QJsonObject& obj) continue; } const QJsonObject reads = eventIt.value().toObject().value("m.read").toObject(); - Receipts receipts; receipts.reserve(reads.size()); + std::vector<Receipt> receipts; + receipts.reserve(static_cast<size_t>(reads.size())); for( auto userIt = reads.begin(); userIt != reads.end(); ++userIt ) { const QJsonObject user = userIt.value().toObject(); - const auto time = QDateTime::fromMSecsSinceEpoch( - static_cast<qint64>(user["ts"].toDouble()), Qt::UTC ); - receipts.push_back({ userIt.key(), time }); + receipts.push_back({userIt.key(), toTimestamp(user["ts"])}); } - e->d->eventsToReceipts.push_back({ eventIt.key(), receipts }); + _eventsWithReceipts.push_back({eventIt.key(), receipts}); } - return e; } + |