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.
This commit is contained in:
Sorunome 2021-08-29 12:29:09 +02:00
parent 024e0de4b9
commit ffb6fd426c
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C
3 changed files with 8 additions and 7 deletions

View File

@ -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<String, BasicRoomEvent> roomAccountData,
@ -383,7 +383,6 @@ class Room {
_oldestSortOrder = oldestSortOrder,
notificationCount = notificationCount ?? 0,
highlightCount = highlightCount ?? 0,
prev_batch = prev_batch ?? '',
roomAccountData = roomAccountData ?? <String, BasicRoomEvent>{},
summary = summary ??
RoomSummary.fromJson({
@ -945,6 +944,9 @@ class Room {
/// the historical events will be published in the onEvent stream.
Future<void> 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;

View File

@ -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;

View File

@ -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);