aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTobias Fella <9750016+TobiasFella@users.noreply.github.com>2021-12-10 16:25:18 +0100
committerGitHub <noreply@github.com>2021-12-10 16:25:18 +0100
commit4a17403f9adad9b4390f7e0010c0f7e23a718f7b (patch)
tree45d454a1c019526a90b887f29deafbc228929ea3 /lib
parentb4a6070d44140a3cbc931b18530721e31f069455 (diff)
downloadlibquotient-4a17403f9adad9b4390f7e0010c0f7e23a718f7b.tar.gz
libquotient-4a17403f9adad9b4390f7e0010c0f7e23a718f7b.zip
Apply suggestions from code review
Co-authored-by: Alexey Rusakov <Kitsune-Ral@users.sf.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/room.cpp16
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;
}
}