From 20740c9976e5f16326dea03b6b2cda933caa1d2e Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sat, 18 Feb 2023 02:59:33 +0100 Subject: Automatically fetch keys for undecrypted messages after verification Also fix rerendering edited messages after keys are received. fixes #1375 fixes #770 fixes #888 --- src/timeline/EventStore.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/timeline/EventStore.cpp') diff --git a/src/timeline/EventStore.cpp b/src/timeline/EventStore.cpp index 2cd16be8..5f118895 100644 --- a/src/timeline/EventStore.cpp +++ b/src/timeline/EventStore.cpp @@ -17,6 +17,7 @@ #include "EventAccessors.h" #include "Logging.h" #include "MatrixClient.h" +#include "TimelineModel.h" #include "UserSettingsPage.h" #include "Utils.h" @@ -353,6 +354,16 @@ EventStore::receivedSessionKey(const std::string &session_id) events_.remove({room_id_, toInternalIdx(*idx)}); emit dataChanged(*idx, *idx); } + + if (auto edit = e.content.relations.replaces()) { + auto edit_idx = idToIndex(edit.value()); + if (edit_idx) { + decryptedEvents_.remove({room_id_, e.event_id}); + events_by_id_.remove({room_id_, e.event_id}); + events_.remove({room_id_, toInternalIdx(*edit_idx)}); + emit dataChanged(*edit_idx, *edit_idx); + } + } } } @@ -538,7 +549,7 @@ EventStore::edits(const std::string &event_id) // spec does not allow changing relatings in an edit. So if we are not using the multi // relation format specific to Nheko, just use the original relations + the edit... if (edit_rel.synthesized) { - auto merged_relations = original_relations; + auto merged_relations = original_relations; merged_relations.synthesized = true; merged_relations.relations.push_back( {mtx::common::RelationType::Replace, event_id}); @@ -753,6 +764,15 @@ EventStore::decryptEvent(const IdIndex &idx, return asCacheEntry(std::move(decryptionResult)); } +void +EventStore::refetchOnlineKeyBackupKeys(TimelineModel *room) +{ + for (const auto &[session_id, request] : room->events.pending_key_requests) { + (void)request; + olm::lookup_keybackup(room->events.room_id_, session_id); + } +} + void EventStore::requestSession(const mtx::events::EncryptedEvent &ev, bool manual) @@ -767,8 +787,8 @@ EventStore::requestSession(const mtx::events::EncryptedEvent