From 48572f8f10382ced66aafddc7090416d7e307623 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Mon, 31 Jan 2022 08:48:10 +0100 Subject: [PATCH] fix: Trigger onChange for index on aggregation event update --- lib/src/room.dart | 5 ++++- lib/src/timeline.dart | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/src/room.dart b/lib/src/room.dart index 67378580..ef796dd5 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -1116,7 +1116,10 @@ class Room { return; } - /// Creates a timeline from the store. Returns a [Timeline] object. + /// Creates a timeline from the store. Returns a [Timeline] object. If you + /// just want to update the whole timeline on every change, use the [onUpdate] + /// callback. For updating only the parts that have changed, use the + /// [onChange], [onRemove] and the [onInsert] callbacks. Future getTimeline({ void Function(int index)? onChange, void Function(int index)? onRemove, diff --git a/lib/src/timeline.dart b/lib/src/timeline.dart index 104462f5..4232dcf4 100644 --- a/lib/src/timeline.dart +++ b/lib/src/timeline.dart @@ -245,6 +245,10 @@ class Timeline { _removeEventFromSet(events, event); // add the new one events.add(event); + if (onChange != null) { + final index = _findEvent(event_id: relationshipEventId); + onChange?.call(index); + } } void removeAggregatedEvent(Event event) { @@ -330,6 +334,7 @@ class Timeline { } addAggregatedEvent(newEvent); + onInsert?.call(index); } }