diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-07-29 17:50:17 +0200 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-07-29 17:51:13 +0200 |
commit | 953d5a9d03b2a3ca439a79775a0c212965d91c20 (patch) | |
tree | 4e0dbc31abddc9603c8f62cb176e6ad5871fd468 /lib/connection.cpp | |
parent | 36344a6e0283f924b72cb2b25001bdf212a7e707 (diff) | |
download | libquotient-953d5a9d03b2a3ca439a79775a0c212965d91c20.tar.gz libquotient-953d5a9d03b2a3ca439a79775a0c212965d91c20.zip |
Moving eventCast()
In a situation where you have an EventPtr that you want to place
somewhere as an `event_ptr_tt<SomeMoreSpecificEventType>` you have to
carefully check that the stored event is actually of
SomeMoreSpecificType and if it is, release() that event pointer,
downcast, and re-wrap it into that new event_ptr_tt - or, as can be seen
from the diff here, re-loadEvent() from JSON, which is simpler but
inefficient. To help clients, and the library, eventCast() can now
accept an rvalue smart pointer and do all the necessary things with it.
Diffstat (limited to 'lib/connection.cpp')
-rw-r--r-- | lib/connection.cpp | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp index 81151135..6e04883e 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -977,22 +977,22 @@ void Connection::Private::consumeToDeviceEvents(Events&& toDeviceEvents) if (!toDeviceEvents.empty()) { qCDebug(E2EE) << "Consuming" << toDeviceEvents.size() << "to-device events"; - visitEach(toDeviceEvents, [this](const EncryptedEvent& event) { - if (event.algorithm() != OlmV1Curve25519AesSha2AlgoKey) { - qCDebug(E2EE) << "Unsupported algorithm" << event.id() - << "for event" << event.algorithm(); - return; - } - if (isKnownCurveKey(event.senderId(), event.senderKey())) { - handleEncryptedToDeviceEvent(event); - return; + for (auto&& tdEvt : toDeviceEvents) + if (auto&& event = eventCast<EncryptedEvent>(std::move(tdEvt))) { + if (event->algorithm() != OlmV1Curve25519AesSha2AlgoKey) { + qCDebug(E2EE) << "Unsupported algorithm" << event->id() + << "for event" << event->algorithm(); + return; + } + if (isKnownCurveKey(event->senderId(), event->senderKey())) { + handleEncryptedToDeviceEvent(*event); + return; + } + trackedUsers += event->senderId(); + outdatedUsers += event->senderId(); + encryptionUpdateRequired = true; + pendingEncryptedEvents.push_back(std::move(event)); } - trackedUsers += event.senderId(); - outdatedUsers += event.senderId(); - encryptionUpdateRequired = true; - pendingEncryptedEvents.push_back( - makeEvent<EncryptedEvent>(event.fullJson())); - }); } #endif } |