diff options
author | Tobias Fella <9750016+TobiasFella@users.noreply.github.com> | 2021-12-10 16:25:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-10 16:25:18 +0100 |
commit | 4a17403f9adad9b4390f7e0010c0f7e23a718f7b (patch) | |
tree | 45d454a1c019526a90b887f29deafbc228929ea3 | |
parent | b4a6070d44140a3cbc931b18530721e31f069455 (diff) | |
download | libquotient-4a17403f9adad9b4390f7e0010c0f7e23a718f7b.tar.gz libquotient-4a17403f9adad9b4390f7e0010c0f7e23a718f7b.zip |
Apply suggestions from code review
Co-authored-by: Alexey Rusakov <Kitsune-Ral@users.sf.net>
-rw-r--r-- | lib/room.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/room.cpp b/lib/room.cpp index 458f870d..0a4fcc68 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -1509,16 +1509,18 @@ void Room::handleRoomKeyEvent(const RoomKeyEvent& roomKeyEvent, qCWarning(E2EE) << "added new inboundGroupSession:" << d->groupSessions.size(); for (const auto& eventId : d->undecryptedEvents[roomKeyEvent.sessionId()]) { - if (!d->eventsIndex.contains(eventId)) { + const auto pIdx = d->eventsIndex.constFind(eventId); + if (pIdx == d->eventsIndex.cend()) continue; - } - auto event = d->timeline.rend() - (d->eventsIndex.value(eventId) - minTimelineIndex() + 1); - if (auto encryptedEvent = event->viewAs<EncryptedEvent>()) { + auto& ti = d->timeline[Timeline::size_type(*pIdx - minTimelineIndex())]; + if (auto encryptedEvent = ti.viewAs<EncryptedEvent>()) { auto decrypted = decryptMessage(*encryptedEvent); if(decrypted) { - auto oldEvent = event->replaceEvent(std::move(decrypted)); - decrypted->setOriginalEvent(std::move(oldEvent)); - emit replacedEvent(event->event(), rawPtr(oldEvent)); + // The reference will survive the pointer being moved + auto& decryptedEvent = *decrypted; + auto oldEvent = ti.replaceEvent(std::move(decrypted)); + decryptedEvent.setOriginalEvent(std::move(oldEvent)); + emit replacedEvent(ti.event(), decrypted->originalEvent()); d->undecryptedEvents[roomKeyEvent.sessionId()] -= eventId; } } |