Merge pull request #1809 from famedly/nico/fix-history-request

fix: canRequestHistory doesn't reflect reality
This commit is contained in:
Nicolas Werner 2024-05-27 15:01:27 +02:00 committed by GitHub
commit 265f889842
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 8 deletions

View File

@ -75,9 +75,13 @@ class Timeline {
// even if /sync's complete while history is being proccessed. // even if /sync's complete while history is being proccessed.
bool _collectHistoryUpdates = false; bool _collectHistoryUpdates = false;
// We confirmed, that there are no more events to load from the database.
bool _fetchedAllDatabaseEvents = false;
bool get canRequestHistory { bool get canRequestHistory {
if (events.isEmpty) return true; if (events.isEmpty) return true;
return room.prev_batch != null && events.last.type != EventTypes.RoomCreate; return !_fetchedAllDatabaseEvents ||
(room.prev_batch != null && events.last.type != EventTypes.RoomCreate);
} }
Future<void> requestHistory( Future<void> requestHistory(
@ -147,20 +151,26 @@ class Timeline {
} }
} }
} else { } else {
_fetchedAllDatabaseEvents = true;
Logs().i('No more events found in the store. Request from server...'); Logs().i('No more events found in the store. Request from server...');
if (isFragmentedTimeline) { if (isFragmentedTimeline) {
await getRoomEvents( await getRoomEvents(
historyCount: historyCount, historyCount: historyCount,
direction: direction, direction: direction,
); );
} else { } else {
await room.requestHistory( if (room.prev_batch == null) {
historyCount: historyCount, Logs().i('No more events to request from server...');
direction: direction, } else {
onHistoryReceived: () { await room.requestHistory(
_collectHistoryUpdates = true; historyCount: historyCount,
}, direction: direction,
); onHistoryReceived: () {
_collectHistoryUpdates = true;
},
);
}
} }
} }
} finally { } finally {
@ -291,6 +301,8 @@ class Timeline {
if (chunk.nextBatch != '') { if (chunk.nextBatch != '') {
allowNewEvent = false; allowNewEvent = false;
isFragmentedTimeline = true; isFragmentedTimeline = true;
// fragmented timelines never read from the database.
_fetchedAllDatabaseEvents = true;
} }
} }