aboutsummaryrefslogtreecommitdiff
path: root/events/receiptevent.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'events/receiptevent.cpp')
-rw-r--r--events/receiptevent.cpp30
1 files changed, 13 insertions, 17 deletions
diff --git a/events/receiptevent.cpp b/events/receiptevent.cpp
index 74e89ba2..5267de4d 100644
--- a/events/receiptevent.cpp
+++ b/events/receiptevent.cpp
@@ -43,7 +43,7 @@ using namespace QMatrixClient;
class ReceiptEvent::Private
{
public:
- QHash<QString, Receipts> eventToReceipts;
+ EventsToReceipts eventsToReceipts;
};
ReceiptEvent::ReceiptEvent()
@@ -57,14 +57,9 @@ ReceiptEvent::~ReceiptEvent()
delete d;
}
-Receipts ReceiptEvent::receiptsForEvent(QString eventId) const
+EventsToReceipts ReceiptEvent::events() const
{
- return d->eventToReceipts.value(eventId);
-}
-
-QStringList ReceiptEvent::events() const
-{
- return d->eventToReceipts.keys();
+ return d->eventsToReceipts;
}
ReceiptEvent* ReceiptEvent::fromJson(const QJsonObject& obj)
@@ -72,18 +67,19 @@ ReceiptEvent* ReceiptEvent::fromJson(const QJsonObject& obj)
ReceiptEvent* e = new ReceiptEvent();
e->parseJson(obj);
const QJsonObject contents = obj["content"].toObject();
- e->d->eventToReceipts.reserve(contents.size());
- for( const QString& eventId: contents.keys() )
+ e->d->eventsToReceipts.reserve(contents.size());
+ for( auto eventIt = contents.begin(); eventIt != contents.end(); ++eventIt )
{
- const QJsonObject reads = contents[eventId].toObject().value("m.read").toObject();
- Receipts receipts(reads.size());
- for( const QString& userId: reads.keys() )
+ const QJsonObject reads = eventIt.value().toObject().value("m.read").toObject();
+ Receipts receipts; receipts.reserve(reads.size());
+ for( auto userIt = reads.begin(); userIt != reads.end(); ++userIt )
{
- const QJsonObject user = reads[userId].toObject();
- const QDateTime time = QDateTime::fromMSecsSinceEpoch( (quint64) user["ts"].toDouble(), Qt::UTC );
- receipts.push_back({ userId, time });
+ 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 });
}
- e->d->eventToReceipts.insert(eventId, receipts);
+ e->d->eventsToReceipts.push_back({ eventIt.key(), receipts });
}
return e;
}