diff --git a/lib/src/timeline.dart b/lib/src/timeline.dart index 55813c26..c85d206e 100644 --- a/lib/src/timeline.dart +++ b/lib/src/timeline.dart @@ -185,7 +185,7 @@ class Timeline { ); if (resp.end == null) { - Logs().w('end parameter was not set in the response'); + Logs().w('We reached the end of the timeline'); } final newNextBatch = direction == Direction.b ? resp.start : resp.end; @@ -195,13 +195,16 @@ class Timeline { ? EventUpdateType.history : EventUpdateType.timeline; - if ((resp.state?.length ?? 0) == 0 && resp.start != resp.end) { + if ((resp.state?.length ?? 0) == 0 && + resp.start != resp.end && + newPrevBatch != null && + newNextBatch != null) { if (type == EventUpdateType.history) { Logs().w( '[nav] we can still request history prevBatch: $type $newPrevBatch'); } else { Logs().w( - '[nav] we can still request history nextBatch: $type $newNextBatch'); + '[nav] we can still request timeline nextBatch: $type $newNextBatch'); } } @@ -209,11 +212,11 @@ class Timeline { resp.chunk.map((e) => Event.fromMatrixEvent(e, room)).toList(); if (!allowNewEvent) { - if (resp.start == resp.end) allowNewEvent = true; + if (resp.start == resp.end || + (resp.end == null && direction == Direction.f)) allowNewEvent = true; if (allowNewEvent) { Logs().d('We now allow sync update into the timeline.'); - allowNewEvent = true; newEvents.addAll( await room.client.database?.getEventList(room, onlySending: true) ?? []); diff --git a/test/fake_matrix_api.dart b/test/fake_matrix_api.dart index 47d4aa72..0497cf4f 100644 --- a/test/fake_matrix_api.dart +++ b/test/fake_matrix_api.dart @@ -266,7 +266,7 @@ class FakeMatrixApi extends MockClient { }; static Map messagesResponseFutureEnd = { 'start': 't789', - 'end': 't789', + 'end': null, 'chunk': [], 'state': [], }; diff --git a/test/timeline_context_test.dart b/test/timeline_context_test.dart index 322250df..20f3ee7d 100644 --- a/test/timeline_context_test.dart +++ b/test/timeline_context_test.dart @@ -130,7 +130,7 @@ void main() { expect(timeline.events[0].eventId, '3143273582443PhrSn:example.org'); expect(timeline.events[1].eventId, '2143273582443PhrSn:example.org'); expect(timeline.events[2].eventId, '1143273582443PhrSn:example.org'); - expect(timeline.chunk.nextBatch, 't789'); + expect(timeline.chunk.nextBatch, ''); expect(timeline.isFragmentedTimeline, true); expect(timeline.allowNewEvent, true);