From ffb6fd426cc8492e10c286f5ad61cd552a55963a Mon Sep 17 00:00:00 2001 From: Sorunome Date: Sun, 29 Aug 2021 12:29:09 +0200 Subject: [PATCH] fix: Requesting history being funky As it turns out, some of the code set the prev_batch for rooms too early to an empty string. For synapse this means "request from the start", for conduit it is just an error. This commit fixes that by never resolving null --> empty string, but instead throw an error. --- lib/src/room.dart | 7 ++++--- lib/src/utils/room_update.dart | 6 +++--- test/client_test.dart | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/src/room.dart b/lib/src/room.dart index 59fe39bc..8d5c0022 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -372,7 +372,7 @@ class Room { this.membership = Membership.join, int notificationCount, int highlightCount, - String prev_batch, + this.prev_batch, this.client, this.notificationSettings, Map roomAccountData, @@ -383,7 +383,6 @@ class Room { _oldestSortOrder = oldestSortOrder, notificationCount = notificationCount ?? 0, highlightCount = highlightCount ?? 0, - prev_batch = prev_batch ?? '', roomAccountData = roomAccountData ?? {}, summary = summary ?? RoomSummary.fromJson({ @@ -945,6 +944,9 @@ class Room { /// the historical events will be published in the onEvent stream. Future requestHistory( {int historyCount = defaultHistoryCount, onHistoryReceived}) async { + if (prev_batch == null) { + throw 'Tried to request history without a prev_batch token'; + } final resp = await client.getRoomEvents( id, prev_batch, @@ -1105,7 +1107,6 @@ class Room { onInsert: onInsert, ); if (client.database == null) { - prev_batch = ''; await requestHistory(historyCount: 10); } return timeline; diff --git a/lib/src/utils/room_update.dart b/lib/src/utils/room_update.dart index 6a8db981..9ea86de0 100644 --- a/lib/src/utils/room_update.dart +++ b/lib/src/utils/room_update.dart @@ -66,7 +66,7 @@ class RoomUpdate { update.unreadNotifications?.notificationCount ?? 0, highlight_count: update.unreadNotifications?.highlightCount ?? 0, limitedTimeline: update.timeline?.limited ?? false, - prev_batch: update.timeline?.prevBatch ?? '', + prev_batch: update.timeline?.prevBatch, summary: update.summary, ) : update is InvitedRoomUpdate @@ -76,7 +76,7 @@ class RoomUpdate { notification_count: 0, highlight_count: 0, limitedTimeline: false, - prev_batch: '', + prev_batch: null, summary: null, ) : update is LeftRoomUpdate @@ -86,7 +86,7 @@ class RoomUpdate { notification_count: 0, highlight_count: 0, limitedTimeline: update.timeline?.limited ?? false, - prev_batch: update.timeline?.prevBatch ?? '', + prev_batch: update.timeline?.prevBatch, summary: null, ) : null; diff --git a/test/client_test.dart b/test/client_test.dart index 52d9584b..84c70cdd 100644 --- a/test/client_test.dart +++ b/test/client_test.dart @@ -233,7 +233,7 @@ void main() { expect(roomUpdateList[1].id == '!696r7674:example.com', true); expect(roomUpdateList[1].membership == Membership.invite, true); - expect(roomUpdateList[1].prev_batch == '', true); + expect(roomUpdateList[1].prev_batch == null, true); expect(roomUpdateList[1].limitedTimeline == false, true); expect(roomUpdateList[1].notification_count == 0, true); expect(roomUpdateList[1].highlight_count == 0, true);