diff --git a/lib/fake_matrix_api.dart b/lib/fake_matrix_api.dart index 34bf8e37..f0b011a7 100644 --- a/lib/fake_matrix_api.dart +++ b/lib/fake_matrix_api.dart @@ -594,7 +594,7 @@ class FakeMatrixApi extends BaseClient { } ], 'limited': true, - 'prev_batch': 't34-23535_0_0', + 'prev_batch': 't44-23535_0_0', }, 'ephemeral': { 'events': [ @@ -711,7 +711,7 @@ class FakeMatrixApi extends BaseClient { }, ], 'limited': true, - 'prev_batch': 't34-23535_0_0', + 'prev_batch': 't34-23535_0_1', }, 'account_data': { 'events': [ diff --git a/lib/src/client.dart b/lib/src/client.dart index 6548bfb3..c593cebe 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -2989,7 +2989,9 @@ 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) { final roomSummaryJson = rooms[roomIndex].summary.toJson() diff --git a/test/client_test.dart b/test/client_test.dart index a6a17416..081b2a5d 100644 --- a/test/client_test.dart +++ b/test/client_test.dart @@ -761,6 +761,31 @@ void main() { expect(room.lastEvent!.content['body'], '* foxies'); }); + test('set prev_batch if in sync', () async { + final roomId = '!726s6s6q:example.com'; + final room = matrix.getRoomById(roomId)!; + + expect(room.prev_batch, 't44-23535_0_0'); + // put an important state event in-memory + await matrix.handleSync( + SyncUpdate.fromJson({ + 'next_batch': 'fakesync', + 'rooms': { + 'join': { + roomId: { + 'timeline': { + 'events': [], + 'prev_batch': 'prev_batch_1', + }, + }, + }, + }, + }), + ); + + expect(room.prev_batch, 'prev_batch_1'); + }); + test('getProfileFromUserId', () async { final cachedProfile = await matrix.getUserProfile('@getme:example.com'); expect(cachedProfile.outdated, false);