aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--events/receiptevent.cpp30
-rw-r--r--events/receiptevent.h5
-rw-r--r--room.cpp9
3 files changed, 18 insertions, 26 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;
}
diff --git a/events/receiptevent.h b/events/receiptevent.h
index 5ca33f75..a7e1debf 100644
--- a/events/receiptevent.h
+++ b/events/receiptevent.h
@@ -36,6 +36,7 @@ Q_DECLARE_TYPEINFO(QMatrixClient::Receipt, Q_MOVABLE_TYPE);
namespace QMatrixClient
{
using Receipts = QVector<Receipt>;
+ using EventsToReceipts = QVector< QPair<QString, Receipts> >;
class ReceiptEvent: public Event
{
@@ -43,9 +44,7 @@ namespace QMatrixClient
ReceiptEvent();
virtual ~ReceiptEvent();
- Receipts receiptsForEvent(QString eventId) const;
-
- QStringList events() const;
+ EventsToReceipts events() const;
static ReceiptEvent* fromJson(const QJsonObject& obj);
diff --git a/room.cpp b/room.cpp
index cb9098d8..9300056a 100644
--- a/room.cpp
+++ b/room.cpp
@@ -603,13 +603,10 @@ void Room::processEphemeralEvent(Event* event)
if( event->type() == EventType::Receipt )
{
auto receiptEvent = static_cast<ReceiptEvent*>(event);
- for( QString eventId: receiptEvent->events() )
- {
- const auto receipts = receiptEvent->receiptsForEvent(eventId);
- for( const Receipt& r: receipts )
+ for( const auto &eventReceiptPair: receiptEvent->events() )
+ for( const Receipt& r: eventReceiptPair.second )
if (auto m = d->member(r.userId))
- d->promoteReadMarker(m, eventId);
- }
+ d->promoteReadMarker(m, eventReceiptPair.first);
}
}