From b8de0f054ba2a2d4bb48916d354a85b821db3e0c Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 28 Jun 2019 10:32:33 +0000 Subject: [PATCH] [Room] Store prevBatch when requesting history --- lib/src/Room.dart | 3 +++ lib/src/Store.dart | 6 ++++++ test/Timeline_test.dart | 1 + 3 files changed, 10 insertions(+) diff --git a/lib/src/Room.dart b/lib/src/Room.dart index 93bf366..be7291b 100644 --- a/lib/src/Room.dart +++ b/lib/src/Room.dart @@ -300,6 +300,9 @@ class Room { if (resp is ErrorResponse) return; + prev_batch = resp["end"]; + client.store?.storeRoomPrevBatch(this); + if (!(resp["chunk"] is List && resp["chunk"].length > 0 && resp["end"] is String)) return; diff --git a/lib/src/Store.dart b/lib/src/Store.dart index fdb436c..d66f047 100644 --- a/lib/src/Store.dart +++ b/lib/src/Store.dart @@ -149,6 +149,12 @@ class Store { return null; } + Future storeRoomPrevBatch(Room room) async { + await _db.rawUpdate( + "UPDATE Rooms SET prev_batch=? WHERE id=?", [room.prev_batch, room.id]); + return null; + } + /// Stores a RoomUpdate object in the database. Must be called inside of /// [transaction]. Future storeRoomUpdate(RoomUpdate roomUpdate) { diff --git a/test/Timeline_test.dart b/test/Timeline_test.dart index 0af61dd..f25383e 100644 --- a/test/Timeline_test.dart +++ b/test/Timeline_test.dart @@ -198,6 +198,7 @@ void main() { expect(timeline.events[6].id, "1143273582443PhrSn:example.org"); expect(timeline.events[7].id, "2143273582443PhrSn:example.org"); expect(timeline.events[8].id, "3143273582443PhrSn:example.org"); + expect(room.prev_batch, "t47409-4357353_219380_26003_2265"); }); }); }