diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2023-07-09 15:41:39 +0200 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2023-07-09 15:42:38 +0200 |
commit | 7fc7aa2da35ee5496c73ba9e29a9b060b1c146e6 (patch) | |
tree | ef657f56fabf24b99aab69ed27c9599c8154370b /src/Cache.cpp | |
parent | Fix mass redaction /command (diff) | |
download | nheko-7fc7aa2da35ee5496c73ba9e29a9b060b1c146e6.tar.xz |
Fix pagination in rooms with a full batch of redactions
Diffstat (limited to 'src/Cache.cpp')
-rw-r--r-- | src/Cache.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp index 3fe2892b..da3e7099 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -3790,10 +3790,27 @@ Cache::saveOldMessages(const std::string &room_id, const mtx::responses::Message } } - nlohmann::json orderEntry = nlohmann::json::object(); - orderEntry["event_id"] = event_id_val; - orderEntry["prev_batch"] = res.end; - orderDb.put(txn, lmdb::to_sv(index), orderEntry.dump()); + if (!event_id_val.empty()) { + nlohmann::json orderEntry = nlohmann::json::object(); + orderEntry["event_id"] = event_id_val; + orderEntry["prev_batch"] = res.end; + orderDb.put(txn, lmdb::to_sv(index), orderEntry.dump()); + } else if (!res.chunk.empty()) { + // to not break pagination, even if all events are redactions we try to persist something in + // the batch. + + nlohmann::json orderEntry = nlohmann::json::object(); + event_id_val = mtx::accessors::event_id(res.chunk.back()); + --index; + + auto event = mtx::accessors::serialize_event(res.chunk.back()).dump(); + eventsDb.put(txn, event_id_val, event); + evToOrderDb.put(txn, event_id_val, lmdb::to_sv(index)); + + orderEntry["event_id"] = event_id_val; + orderEntry["prev_batch"] = res.end; + orderDb.put(txn, lmdb::to_sv(index), orderEntry.dump()); + } txn.commit(); |