From 8e7db020bfb7a96fb4632a57a7a764ca46e11729 Mon Sep 17 00:00:00 2001 From: Krille Fear Date: Mon, 7 Feb 2022 15:06:38 +0100 Subject: [PATCH 1/3] fix: Remove aggregation event doesnt trigger onChange --- lib/src/timeline.dart | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/src/timeline.dart b/lib/src/timeline.dart index 6b9a01f6..7559a487 100644 --- a/lib/src/timeline.dart +++ b/lib/src/timeline.dart @@ -260,6 +260,13 @@ class Timeline { _removeEventFromSet(events, event); } } + if (onChange != null) { + final relationshipEventId = event.relationshipEventId; + if (relationshipEventId != null) { + final index = _findEvent(event_id: relationshipEventId); + onChange?.call(index); + } + } } void _handleEventUpdate(EventUpdate eventUpdate, {bool update = true}) { From 84e87279e8345834c659b42b83d350fe2da00c7e Mon Sep 17 00:00:00 2001 From: Krille Fear Date: Mon, 7 Feb 2022 15:15:44 +0100 Subject: [PATCH 2/3] fix: Remove onHistoryReceived which was broken anyway --- lib/src/room.dart | 2 -- lib/src/timeline.dart | 13 +++++++------ test/timeline_test.dart | 5 +---- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/src/room.dart b/lib/src/room.dart index 8db6686a..894be747 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -1140,7 +1140,6 @@ class Room { void Function(int index)? onRemove, void Function(int insertID)? onInsert, void Function()? onUpdate, - void Function(int count)? onHistoryReceived, }) async { await postLoad(); var events; @@ -1170,7 +1169,6 @@ class Room { onRemove: onRemove, onInsert: onInsert, onUpdate: onUpdate, - onHistoryReceived: onHistoryReceived, ); if (client.database == null) { await requestHistory(historyCount: 10); diff --git a/lib/src/timeline.dart b/lib/src/timeline.dart index 7559a487..f82cf4a0 100644 --- a/lib/src/timeline.dart +++ b/lib/src/timeline.dart @@ -36,7 +36,6 @@ class Timeline { final void Function(int index)? onChange; final void Function(int index)? onInsert; final void Function(int index)? onRemove; - final void Function(int count)? onHistoryReceived; StreamSubscription? sub; StreamSubscription? roomSub; @@ -87,16 +86,19 @@ class Timeline { ); if (eventsFromStore != null && eventsFromStore.isNotEmpty) { 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 { Logs().v('No more events found in the store. Request from server...'); - final count = await room.requestHistory( + await room.requestHistory( historyCount: historyCount, onHistoryReceived: () { _collectHistoryUpdates = true; }, ); - onHistoryReceived?.call(count); } } finally { _collectHistoryUpdates = false; @@ -112,7 +114,6 @@ class Timeline { this.onChange, this.onInsert, this.onRemove, - this.onHistoryReceived, }) : events = events ?? [] { sub = room.client.onEvent.stream.listen(_handleEventUpdate); @@ -338,8 +339,8 @@ class Timeline { } else { index = events.firstIndexWhereNotError; events.insert(index, newEvent); - onInsert?.call(index); } + onInsert?.call(index); addAggregatedEvent(newEvent); } diff --git a/test/timeline_test.dart b/test/timeline_test.dart index 0f4d2672..56f0ef74 100644 --- a/test/timeline_test.dart +++ b/test/timeline_test.dart @@ -31,7 +31,6 @@ void main() { final insertList = []; final changeList = []; final removeList = []; - final historyRequestList = []; var olmEnabled = true; late Client client; @@ -60,7 +59,6 @@ void main() { onInsert: insertList.add, onChange: changeList.add, onRemove: removeList.add, - onHistoryReceived: historyRequestList.add, ); }); @@ -293,8 +291,7 @@ void main() { await Future.delayed(Duration(milliseconds: 50)); expect(updateCount, 20); - expect(insertList, [0, 0, 0, 0, 0, 0, 1, 2, 0]); - expect(historyRequestList, []); + expect(insertList, [0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 1, 2]); expect(timeline.events.length, 3); expect(timeline.events[0].eventId, '3143273582443PhrSn:example.org'); expect(timeline.events[1].eventId, '2143273582443PhrSn:example.org'); From ec367e9bc15e8eff0fb72e5fd4455bb6e1f77d16 Mon Sep 17 00:00:00 2001 From: Krille Fear Date: Mon, 7 Feb 2022 15:16:23 +0100 Subject: [PATCH 3/3] chore: Bump version --- CHANGELOG.md | 4 ++++ pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67df0318..9c198d28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [0.8.3] - 07nd Feb 2022 +- fix: Remove onHistoryReceived which was broken anyway +- fix: Remove aggregation event doesnt trigger onChange + ## [0.8.2] - 04nd Feb 2022 - fix: Add redaction events to timeline - fix: Resize image with compute by using const class arguments diff --git a/pubspec.yaml b/pubspec.yaml index 557b6496..776cbca7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: matrix description: Matrix Dart SDK -version: 0.8.2 +version: 0.8.3 homepage: https://famedly.com repository: https://gitlab.com/famedly/company/frontend/famedlysdk.git