fix(timeline): when reloading a fresh timeline, also reload the related events

This commit is contained in:
Benjamin Bouvier
2025-07-07 16:41:49 +02:00
parent bbbcec5963
commit 96fbbd3cd8
3 changed files with 43 additions and 0 deletions

View File

@@ -380,12 +380,33 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
let (events, _) = room_event_cache.subscribe_to_thread(root_event_id.clone()).await;
let has_events = !events.is_empty();
// For each event, we also need to find the related events, as they don't
// include the thread relationship, they won't be included in
// the initial list of events.
let mut related_events = Vector::new();
for event_id in events.iter().filter_map(|event| event.event_id()) {
if let Some((_original, related)) =
room_event_cache.find_event_with_relations(&event_id, None).await
{
related_events.extend(related);
}
}
self.replace_with_initial_remote_events(
events.into_iter(),
RemoteEventOrigin::Cache,
)
.await;
// Now that we've inserted the thread events, add the aggregations too.
if !related_events.is_empty() {
self.handle_remote_aggregations(
vec![VectorDiff::Append { values: related_events }],
RemoteEventOrigin::Cache,
)
.await;
}
Ok(has_events)
}

View File

@@ -46,6 +46,8 @@ impl super::Timeline {
Ok(self.live_paginate_backwards(num_events).await?)
} else if let Some(thread_root) = self.controller.thread_root() {
// Note: in the future (when the event cache implements persistent storage for
// threads), we might need to load the related events too here.
Ok(self.event_cache.paginate_thread_backwards(thread_root, num_events).await?)
} else {
Ok(self.controller.focused_paginate_backwards(num_events).await?)

View File

@@ -655,6 +655,26 @@ async fn test_thread_timeline_gets_related_events_from_sync() {
let event_item = value.as_event().unwrap();
assert_eq!(event_item.event_id().unwrap(), threaded_event_id);
assert!(event_item.content().reactions().unwrap().is_empty().not());
// If I open another timeline on the same thread, I still see the related event.
let other_timeline = room
.timeline_builder()
.with_focus(TimelineFocus::Thread { root_event_id: thread_root_event_id })
.build()
.await
.unwrap();
let (initial_items, _thread_stream) = other_timeline.subscribe().await;
assert_eq!(initial_items.len(), 2);
// The date divider.
assert!(initial_items[0].is_date_divider());
// The threaded event with the reaction.
let event_item = initial_items[1].as_event().unwrap();
assert_eq!(event_item.event_id(), Some(threaded_event_id));
assert!(event_item.content().reactions().unwrap().is_empty().not());
}
#[async_test]