From 0d084d8824b256d127409ae6d3d336184612530c Mon Sep 17 00:00:00 2001 From: Karthikeyan S Date: Thu, 13 Mar 2025 10:05:05 +0530 Subject: [PATCH] fix: room prev_batch set incorrectly follow-up --- lib/src/client.dart | 3 --- lib/src/room.dart | 14 ++++++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index 3be0d26e..6d304717 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -2988,9 +2988,6 @@ class Client extends MatrixApi { chatUpdate.unreadNotifications?.notificationCount ?? 0; rooms[roomIndex].highlightCount = chatUpdate.unreadNotifications?.highlightCount ?? 0; - if (chatUpdate.timeline?.prevBatch != null) { - rooms[roomIndex].prev_batch = chatUpdate.timeline?.prevBatch; - } final summary = chatUpdate.summary; if (summary != null) { diff --git a/lib/src/room.dart b/lib/src/room.dart index 77338324..51b4165f 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -1322,7 +1322,6 @@ class Room { ); if (onHistoryReceived != null) onHistoryReceived(); - final newPrevBatch = direction == Direction.b ? resp.end : resp.start; Future loadFn() async { if (!((resp.chunk.isNotEmpty) && resp.end != null)) return; @@ -1340,7 +1339,8 @@ class Room { events: direction == Direction.b ? resp.chunk : resp.chunk.reversed.toList(), - prevBatch: newPrevBatch, + prevBatch: + direction == Direction.b ? resp.end : resp.start, ), ), } @@ -1354,21 +1354,23 @@ class Room { events: direction == Direction.b ? resp.chunk : resp.chunk.reversed.toList(), - prevBatch: newPrevBatch, + prevBatch: + direction == Direction.b ? resp.end : resp.start, ), ), } : null, ), ), - direction: Direction.b, + direction: direction, ); } if (client.database != null) { await client.database?.transaction(() async { - if (storeInDatabase) { - await client.database?.setRoomPrevBatch(newPrevBatch, id, client); + if (storeInDatabase && direction == Direction.b) { + this.prev_batch = resp.end; + await client.database?.setRoomPrevBatch(resp.end, id, client); } await loadFn(); });