summary refs log tree commit diff
path: root/src/timeline
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-06-19 01:46:23 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2021-06-25 11:35:24 +0200
commitd30446a8b39c70f87fad34b0c1958236c9f227cc (patch)
tree62df9738a32d962291640c3d0e0d5574a645c1e7 /src/timeline
parentFix missing back button on spaces page in narrow mode as well as topic not re... (diff)
downloadnheko-d30446a8b39c70f87fad34b0c1958236c9f227cc.tar.xz
Don't spam key requests directly after startup
Diffstat (limited to 'src/timeline')
-rw-r--r--src/timeline/EventStore.cpp15
-rw-r--r--src/timeline/EventStore.h2
-rw-r--r--src/timeline/TimelineModel.cpp6
3 files changed, 23 insertions, 0 deletions
diff --git a/src/timeline/EventStore.cpp b/src/timeline/EventStore.cpp
index 04f7ef76..9a91ff79 100644
--- a/src/timeline/EventStore.cpp
+++ b/src/timeline/EventStore.cpp
@@ -675,6 +675,9 @@ EventStore::decryptEvent(const IdIndex &idx,
                                               index.room_id,
                                               index.session_id,
                                               e.sender);
+                        // we may not want to request keys during initial sync and such
+                        if (suppressKeyRequests)
+                                break;
                         // TODO: Check if this actually works and look in key backup
                         auto copy    = e;
                         copy.room_id = room_id_;
@@ -816,6 +819,18 @@ EventStore::decryptEvent(const IdIndex &idx,
         return asCacheEntry(std::move(decryptionResult.event.value()));
 }
 
+void
+EventStore::enableKeyRequests(bool suppressKeyRequests_)
+{
+        if (!suppressKeyRequests_) {
+                for (const auto &key : decryptedEvents_.keys())
+                        if (key.room == this->room_id_)
+                                decryptedEvents_.remove(key);
+                suppressKeyRequests = false;
+        } else
+                suppressKeyRequests = true;
+}
+
 mtx::events::collections::TimelineEvents *
 EventStore::get(std::string id, std::string_view related_to, bool decrypt, bool resolve_edits)
 {
diff --git a/src/timeline/EventStore.h b/src/timeline/EventStore.h
index d9bb86cb..7c404102 100644
--- a/src/timeline/EventStore.h
+++ b/src/timeline/EventStore.h
@@ -115,6 +115,7 @@ public slots:
         void addPending(mtx::events::collections::TimelineEvents event);
         void receivedSessionKey(const std::string &session_id);
         void clearTimeline();
+        void enableKeyRequests(bool suppressKeyRequests_);
 
 private:
         std::vector<mtx::events::collections::TimelineEvents> edits(const std::string &event_id);
@@ -142,4 +143,5 @@ private:
         std::string current_txn;
         int current_txn_error_count = 0;
         bool noMoreMessages         = false;
+        bool suppressKeyRequests    = true;
 };
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 13919e6d..067f219a 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -379,6 +379,7 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
         connect(&events, &EventStore::updateFlowEventId, this, [this](std::string event_id) {
                 this->updateFlowEventId(event_id);
         });
+
         // When a message is sent, check if the current edit/reply relates to that message,
         // and update the event_id so that it points to the sent message and not the pending one.
         connect(&events,
@@ -395,6 +396,11 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
                         }
                 });
 
+        connect(manager_,
+                &TimelineViewManager::initialSyncChanged,
+                &events,
+                &EventStore::enableKeyRequests);
+
         showEventTimer.callOnTimeout(this, &TimelineModel::scrollTimerEvent);
 }