diff --git a/src/timeline/EventStore.cpp b/src/timeline/EventStore.cpp
index d3c5c3fa..3564ffc0 100644
--- a/src/timeline/EventStore.cpp
+++ b/src/timeline/EventStore.cpp
@@ -54,6 +54,9 @@ EventStore::EventStore(std::string room_id, QObject *)
&EventStore::oldMessagesRetrieved,
this,
[this](const mtx::responses::Messages &res) {
+ if (cache::client()->previousBatchToken(room_id_) == res.end)
+ noMoreMessages = true;
+
uint64_t newFirst = cache::client()->saveOldMessages(room_id_, res);
if (newFirst == first)
fetchMore();
@@ -687,6 +690,9 @@ EventStore::get(std::string_view id, std::string_view related_to, bool decrypt)
void
EventStore::fetchMore()
{
+ if (noMoreMessages)
+ return;
+
mtx::http::MessagesOpts opts;
opts.room_id = room_id_;
opts.from = cache::client()->previousBatchToken(room_id_);
diff --git a/src/timeline/EventStore.h b/src/timeline/EventStore.h
index 954e271c..7f8e2396 100644
--- a/src/timeline/EventStore.h
+++ b/src/timeline/EventStore.h
@@ -123,4 +123,5 @@ private:
std::string current_txn;
int current_txn_error_count = 0;
+ bool noMoreMessages = false;
};
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 359e95bc..5db6aa00 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -1138,7 +1138,8 @@ TimelineModel::handleClaimedKeys(
pks.at(user_id).at(device_id).curve25519);
try {
- cache::saveOlmSession(id_key, std::move(s));
+ cache::saveOlmSession(
+ id_key, std::move(s), QDateTime::currentMSecsSinceEpoch());
} catch (const lmdb::error &e) {
nhlog::db()->critical("failed to save outbound olm session: {}",
e.what());
|