summary refs log tree commit diff
path: root/src/timeline
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2023-02-18 02:59:33 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2023-02-18 03:08:23 +0100
commit20740c9976e5f16326dea03b6b2cda933caa1d2e (patch)
tree58f57e04ccfff8e47554b12eea7c0ece867f2e29 /src/timeline
parentFix edits in other clients jumping out of threads (diff)
downloadnheko-20740c9976e5f16326dea03b6b2cda933caa1d2e.tar.xz
Automatically fetch keys for undecrypted messages after verification
Also fix rerendering edited messages after keys are received.

fixes #1375
fixes #770
fixes #888
Diffstat (limited to 'src/timeline')
-rw-r--r--src/timeline/EventStore.cpp26
-rw-r--r--src/timeline/EventStore.h4
-rw-r--r--src/timeline/RoomlistModel.cpp12
-rw-r--r--src/timeline/RoomlistModel.h2
-rw-r--r--src/timeline/TimelineModel.h2
5 files changed, 43 insertions, 3 deletions
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}); @@ -754,6 +765,15 @@ EventStore::decryptEvent(const IdIndex &idx, } 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<mtx::events::msg::Encrypted> &ev, bool manual) { @@ -767,8 +787,8 @@ EventStore::requestSession(const mtx::events::EncryptedEvent<mtx::events::msg::E auto &r = pending_key_requests.at(ev.content.session_id); r.events.push_back(copy); - // automatically request once every 10 min, manually every 1 min - qint64 delay = manual ? 60 : (60 * 10); + // automatically request once every 2 min, manually every 30 s + qint64 delay = manual ? 30 : (60 * 2); if (r.requested_at + delay < QDateTime::currentSecsSinceEpoch()) { r.requested_at = QDateTime::currentSecsSinceEpoch(); olm::lookup_keybackup(room_id_, ev.content.session_id); diff --git a/src/timeline/EventStore.h b/src/timeline/EventStore.h
index bfca7dbe..45dc0169 100644 --- a/src/timeline/EventStore.h +++ b/src/timeline/EventStore.h
@@ -20,6 +20,8 @@ #include "Reaction.h" #include "encryption/Olm.h" +class TimelineModel; + class EventStore final : public QObject { Q_OBJECT @@ -27,6 +29,8 @@ class EventStore final : public QObject public: EventStore(std::string room_id, QObject *parent); + static void refetchOnlineKeyBackupKeys(TimelineModel *room); + // taken from QtPrivate::QHashCombine static uint hashCombine(uint hash, uint seed) { diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp
index 5bd12a36..c4826453 100644 --- a/src/timeline/RoomlistModel.cpp +++ b/src/timeline/RoomlistModel.cpp
@@ -812,6 +812,18 @@ RoomlistModel::setCurrentRoom(const QString &roomid) } } +void +RoomlistModel::refetchOnlineKeyBackupKeys() +{ + for (auto i = models.begin(); i != models.end(); ++i) { + auto ptr = i.value(); + + if (!ptr.isNull()) { + EventStore::refetchOnlineKeyBackupKeys(ptr.data()); + } + } +} + namespace { enum NotificationImportance : short { diff --git a/src/timeline/RoomlistModel.h b/src/timeline/RoomlistModel.h
index 4b312ddc..8f7694b7 100644 --- a/src/timeline/RoomlistModel.h +++ b/src/timeline/RoomlistModel.h
@@ -95,6 +95,8 @@ public: } RoomPreview getRoomPreviewById(QString roomid) const; + void refetchOnlineKeyBackupKeys(); + public slots: void initializeRooms(); void sync(const mtx::responses::Sync &sync_); diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h
index 334a4d6f..f753f24d 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h
@@ -528,6 +528,8 @@ private: std::unique_ptr<RoomSummary, DeleteLaterDeleter> parentSummary = nullptr; bool parentChecked = false; + + friend void EventStore::refetchOnlineKeyBackupKeys(TimelineModel *room); }; template<class T>