summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2020-10-23 19:42:12 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2020-10-23 19:42:23 +0200
commit4797b9fa9651c2bb5a35ca67497c2f0eb4956820 (patch)
treec25af0ef6625dc99cd04a7b564743d5a97edefcd
parentFix share keys setting not working (diff)
downloadnheko-4797b9fa9651c2bb5a35ca67497c2f0eb4956820.tar.xz
Fix infinite pagination properly now.
-rw-r--r--src/Cache.cpp13
-rw-r--r--src/TextInputWidget.cpp4
-rw-r--r--src/Utils.cpp2
-rw-r--r--src/timeline/EventStore.cpp5
4 files changed, 19 insertions, 5 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp
index 090af913..3ffa9fd2 100644
--- a/src/Cache.cpp
+++ b/src/Cache.cpp
@@ -2712,8 +2712,19 @@ Cache::saveOldMessages(const std::string &room_id, const mtx::responses::Message
                 }
         }
 
-        if (res.chunk.empty())
+        if (res.chunk.empty()) {
+                if (lmdb::dbi_get(txn, orderDb, lmdb::val(&index, sizeof(index)), val)) {
+                        auto orderEntry = json::parse(std::string_view(val.data(), val.size()));
+                        orderEntry["prev_batch"] = res.end;
+                        lmdb::dbi_put(txn,
+                                      orderDb,
+                                      lmdb::val(&index, sizeof(index)),
+                                      lmdb::val(orderEntry.dump()));
+                        nhlog::db()->debug("saving '{}'", orderEntry.dump());
+                        txn.commit();
+                }
                 return index;
+        }
 
         std::string event_id_val;
         for (const auto &e : res.chunk) {
diff --git a/src/TextInputWidget.cpp b/src/TextInputWidget.cpp
index 37a65f9e..22e8aafc 100644
--- a/src/TextInputWidget.cpp
+++ b/src/TextInputWidget.cpp
@@ -450,8 +450,8 @@ FilteredTextEdit::completerRect()
         auto item_height = completer_->popup()->sizeHintForRow(0);
         auto max_height  = item_height * completer_->maxVisibleItems();
         auto height      = (completer_->completionCount() > completer_->maxVisibleItems())
-                             ? max_height
-                             : completer_->completionCount() * item_height;
+                        ? max_height
+                        : completer_->completionCount() * item_height;
         rect.setWidth(completer_->popup()->sizeHintForColumn(0));
         rect.moveBottom(-height);
         return rect;
diff --git a/src/Utils.cpp b/src/Utils.cpp
index 38dbba22..0bfc82c3 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -638,7 +638,7 @@ utils::luminance(const QColor &col)
         qreal lumRgb[3];
 
         for (int i = 0; i < 3; i++) {
-                qreal v = colRgb[i] / 255.0;
+                qreal v                  = colRgb[i] / 255.0;
                 v <= 0.03928 ? lumRgb[i] = v / 12.92 : lumRgb[i] = qPow((v + 0.055) / 1.055, 2.4);
         }
 
diff --git a/src/timeline/EventStore.cpp b/src/timeline/EventStore.cpp
index 22809a20..38292f49 100644
--- a/src/timeline/EventStore.cpp
+++ b/src/timeline/EventStore.cpp
@@ -54,8 +54,11 @@ EventStore::EventStore(std::string room_id, QObject *)
           &EventStore::oldMessagesRetrieved,
           this,
           [this](const mtx::responses::Messages &res) {
-                  if (cache::client()->previousBatchToken(room_id_) == res.end)
+                  if (cache::client()->previousBatchToken(room_id_) == res.end) {
                           noMoreMessages = true;
+                          emit fetchedMore();
+                          return;
+                  }
 
                   uint64_t newFirst = cache::client()->saveOldMessages(room_id_, res);
                   if (newFirst == first)