fix: Remove onHistoryReceived which was broken anyway

This commit is contained in:
Krille Fear 2022-02-07 15:15:44 +01:00
parent 8e7db020bf
commit 84e87279e8
3 changed files with 8 additions and 12 deletions

View File

@ -1140,7 +1140,6 @@ class Room {
void Function(int index)? onRemove, void Function(int index)? onRemove,
void Function(int insertID)? onInsert, void Function(int insertID)? onInsert,
void Function()? onUpdate, void Function()? onUpdate,
void Function(int count)? onHistoryReceived,
}) async { }) async {
await postLoad(); await postLoad();
var events; var events;
@ -1170,7 +1169,6 @@ class Room {
onRemove: onRemove, onRemove: onRemove,
onInsert: onInsert, onInsert: onInsert,
onUpdate: onUpdate, onUpdate: onUpdate,
onHistoryReceived: onHistoryReceived,
); );
if (client.database == null) { if (client.database == null) {
await requestHistory(historyCount: 10); await requestHistory(historyCount: 10);

View File

@ -36,7 +36,6 @@ class Timeline {
final void Function(int index)? onChange; final void Function(int index)? onChange;
final void Function(int index)? onInsert; final void Function(int index)? onInsert;
final void Function(int index)? onRemove; final void Function(int index)? onRemove;
final void Function(int count)? onHistoryReceived;
StreamSubscription<EventUpdate>? sub; StreamSubscription<EventUpdate>? sub;
StreamSubscription<SyncUpdate>? roomSub; StreamSubscription<SyncUpdate>? roomSub;
@ -87,16 +86,19 @@ class Timeline {
); );
if (eventsFromStore != null && eventsFromStore.isNotEmpty) { if (eventsFromStore != null && eventsFromStore.isNotEmpty) {
events.addAll(eventsFromStore); events.addAll(eventsFromStore);
onHistoryReceived?.call(eventsFromStore.length); final startIndex = events.length - eventsFromStore.length;
final endIndex = events.length;
for (var i = startIndex; i < endIndex; i++) {
onInsert?.call(i);
}
} else { } else {
Logs().v('No more events found in the store. Request from server...'); Logs().v('No more events found in the store. Request from server...');
final count = await room.requestHistory( await room.requestHistory(
historyCount: historyCount, historyCount: historyCount,
onHistoryReceived: () { onHistoryReceived: () {
_collectHistoryUpdates = true; _collectHistoryUpdates = true;
}, },
); );
onHistoryReceived?.call(count);
} }
} finally { } finally {
_collectHistoryUpdates = false; _collectHistoryUpdates = false;
@ -112,7 +114,6 @@ class Timeline {
this.onChange, this.onChange,
this.onInsert, this.onInsert,
this.onRemove, this.onRemove,
this.onHistoryReceived,
}) : events = events ?? [] { }) : events = events ?? [] {
sub = room.client.onEvent.stream.listen(_handleEventUpdate); sub = room.client.onEvent.stream.listen(_handleEventUpdate);
@ -338,8 +339,8 @@ class Timeline {
} else { } else {
index = events.firstIndexWhereNotError; index = events.firstIndexWhereNotError;
events.insert(index, newEvent); events.insert(index, newEvent);
onInsert?.call(index);
} }
onInsert?.call(index);
addAggregatedEvent(newEvent); addAggregatedEvent(newEvent);
} }

View File

@ -31,7 +31,6 @@ void main() {
final insertList = <int>[]; final insertList = <int>[];
final changeList = <int>[]; final changeList = <int>[];
final removeList = <int>[]; final removeList = <int>[];
final historyRequestList = <int>[];
var olmEnabled = true; var olmEnabled = true;
late Client client; late Client client;
@ -60,7 +59,6 @@ void main() {
onInsert: insertList.add, onInsert: insertList.add,
onChange: changeList.add, onChange: changeList.add,
onRemove: removeList.add, onRemove: removeList.add,
onHistoryReceived: historyRequestList.add,
); );
}); });
@ -293,8 +291,7 @@ void main() {
await Future.delayed(Duration(milliseconds: 50)); await Future.delayed(Duration(milliseconds: 50));
expect(updateCount, 20); expect(updateCount, 20);
expect(insertList, [0, 0, 0, 0, 0, 0, 1, 2, 0]); expect(insertList, [0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 1, 2]);
expect(historyRequestList, []);
expect(timeline.events.length, 3); expect(timeline.events.length, 3);
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');