fix: request history

This commit is contained in:
Henri Carnot 2022-07-05 13:24:35 +00:00 committed by Nicolas Werner
parent 8b307722a9
commit 65b20e7d17
3 changed files with 10 additions and 7 deletions

View File

@ -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) ??
[]);

View File

@ -266,7 +266,7 @@ class FakeMatrixApi extends MockClient {
};
static Map<String, dynamic> messagesResponseFutureEnd = {
'start': 't789',
'end': 't789',
'end': null,
'chunk': [],
'state': [],
};

View File

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