From 950fcd289dcbfe04cc5562e5c88e0eb8f5a9f648 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Tue, 31 Mar 2026 10:31:25 +0200 Subject: [PATCH] refactor(ffi): only start with a reset diff if the timeline isn't empty --- bindings/matrix-sdk-ffi/src/timeline/mod.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/timeline/mod.rs b/bindings/matrix-sdk-ffi/src/timeline/mod.rs index 286231f51..59adacafb 100644 --- a/bindings/matrix-sdk-ffi/src/timeline/mod.rs +++ b/bindings/matrix-sdk-ffi/src/timeline/mod.rs @@ -284,8 +284,17 @@ impl Timeline { // be that the listener be called before the initial items have been // handled by the caller. See #3535 for details. - // First, pass all the items as a reset update. - listener.on_update(vec![TimelineDiff::new(VectorDiff::Reset { values: timeline_items })]); + // Note we pass initial items as a reset update, as a way to give the callers a + // unified way to handle the initial batch of items as well as other + // batches, instead of having a separate callback for the initial items. + // + // Start with passing all the items of a *non-empty* timeline as a reset update + // (if the initial items are empty, then the timeline would transition + // from empty to empty, which is a no-op). + if !timeline_items.is_empty() { + listener + .on_update(vec![TimelineDiff::new(VectorDiff::Reset { values: timeline_items })]); + } Arc::new(TaskHandle::new(get_runtime_handle().spawn(async move { pin_mut!(timeline_stream);