diff options
author | Felix Rohrbach <fxrh@gmx.de> | 2016-08-23 18:35:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-23 18:35:40 +0200 |
commit | 77d45e9afa195f7d715a5074b16f16c6b2d15235 (patch) | |
tree | b8c9f1d73e0eba48cc55194b06bbbeb97bc4e258 /events/receiptevent.cpp | |
parent | da52097f1c90d7286aff27a84fc14b6b0793ff97 (diff) | |
parent | fb6df81fa9f224c94118fd79fea91ae15559c7e3 (diff) | |
download | libquotient-77d45e9afa195f7d715a5074b16f16c6b2d15235.tar.gz libquotient-77d45e9afa195f7d715a5074b16f16c6b2d15235.zip |
Merge pull request #18 from Fxrh/kitsune-use-qvector-with-nonpointers
Replaced QList<> with QVector<> where appropriate + minor code cleanup
Diffstat (limited to 'events/receiptevent.cpp')
-rw-r--r-- | events/receiptevent.cpp | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/events/receiptevent.cpp b/events/receiptevent.cpp index d2a27079..29d78a20 100644 --- a/events/receiptevent.cpp +++ b/events/receiptevent.cpp @@ -41,17 +41,11 @@ Example of a Receipt Event: using namespace QMatrixClient; -Receipt::Receipt(QString event, QString user, QDateTime time) - : eventId(event) - , userId(user) - , timestamp(time) -{ -} class ReceiptEvent::Private { public: - QHash<QString, QList<Receipt>> eventToReceipts; + QHash<QString, Receipts> eventToReceipts; }; ReceiptEvent::ReceiptEvent() @@ -65,7 +59,7 @@ ReceiptEvent::~ReceiptEvent() delete d; } -QList<Receipt> ReceiptEvent::receiptsForEvent(QString eventId) const +Receipts ReceiptEvent::receiptsForEvent(QString eventId) const { return d->eventToReceipts.value(eventId); } @@ -79,17 +73,17 @@ ReceiptEvent* ReceiptEvent::fromJson(const QJsonObject& obj) { ReceiptEvent* e = new ReceiptEvent(); e->parseJson(obj); - const QJsonObject contents = obj.value("content").toObject(); + const QJsonObject contents = obj["content"].toObject(); + e->d->eventToReceipts.reserve(contents.size()); for( const QString& eventId: contents.keys() ) { - QJsonObject reads = contents.value(eventId).toObject().value("m.read").toObject(); - QList<Receipt> receipts; + const QJsonObject reads = contents[eventId].toObject().value("m.read").toObject(); + Receipts receipts(reads.size()); for( const QString& userId: reads.keys() ) { - QJsonObject user = reads.value(userId).toObject(); - QDateTime time = QDateTime::fromMSecsSinceEpoch( (quint64) user.value("ts").toDouble(), Qt::UTC ); - Receipt receipt(eventId, userId, time); - receipts.append(receipt); + const QJsonObject user = reads[userId].toObject(); + const QDateTime time = QDateTime::fromMSecsSinceEpoch( (quint64) user["ts"].toDouble(), Qt::UTC ); + receipts.push_back({ eventId, userId, time }); } e->d->eventToReceipts.insert(eventId, receipts); } |