Merge branch 'henri/fix-request-history' into 'main'

fix: request history

See merge request famedly/company/frontend/famedlysdk!1070
This commit is contained in:
Nicolas Werner 2022-07-05 13:24:36 +00:00
commit 01e16506dc
3 changed files with 10 additions and 7 deletions

View File

@ -185,7 +185,7 @@ class Timeline {
); );
if (resp.end == null) { 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; final newNextBatch = direction == Direction.b ? resp.start : resp.end;
@ -195,13 +195,16 @@ class Timeline {
? EventUpdateType.history ? EventUpdateType.history
: EventUpdateType.timeline; : 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) { if (type == EventUpdateType.history) {
Logs().w( Logs().w(
'[nav] we can still request history prevBatch: $type $newPrevBatch'); '[nav] we can still request history prevBatch: $type $newPrevBatch');
} else { } else {
Logs().w( 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(); resp.chunk.map((e) => Event.fromMatrixEvent(e, room)).toList();
if (!allowNewEvent) { if (!allowNewEvent) {
if (resp.start == resp.end) allowNewEvent = true; if (resp.start == resp.end ||
(resp.end == null && direction == Direction.f)) allowNewEvent = true;
if (allowNewEvent) { if (allowNewEvent) {
Logs().d('We now allow sync update into the timeline.'); Logs().d('We now allow sync update into the timeline.');
allowNewEvent = true;
newEvents.addAll( newEvents.addAll(
await room.client.database?.getEventList(room, onlySending: true) ?? await room.client.database?.getEventList(room, onlySending: true) ??
[]); []);

View File

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

View File

@ -130,7 +130,7 @@ void main() {
expect(timeline.events[0].eventId, '3143273582443PhrSn:example.org'); expect(timeline.events[0].eventId, '3143273582443PhrSn:example.org');
expect(timeline.events[1].eventId, '2143273582443PhrSn:example.org'); expect(timeline.events[1].eventId, '2143273582443PhrSn:example.org');
expect(timeline.events[2].eventId, '1143273582443PhrSn: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.isFragmentedTimeline, true);
expect(timeline.allowNewEvent, true); expect(timeline.allowNewEvent, true);