From 53732e0ff2227f1f8982da3ca55bcfa061cbae42 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Mon, 24 Mar 2025 17:06:28 +0100 Subject: [PATCH] refactor(timeline): use `load_or_fetch_event` when fetching a reply's content --- crates/matrix-sdk-ui/src/timeline/controller/mod.rs | 4 +--- crates/matrix-sdk-ui/src/timeline/mod.rs | 3 +-- .../tests/integration/timeline/replies.rs | 10 ---------- 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/crates/matrix-sdk-ui/src/timeline/controller/mod.rs b/crates/matrix-sdk-ui/src/timeline/controller/mod.rs index 1c66fc355..4cb65f3c5 100644 --- a/crates/matrix-sdk-ui/src/timeline/controller/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/controller/mod.rs @@ -1529,9 +1529,7 @@ async fn fetch_replied_to_event( drop(state); trace!("Fetching replied-to event"); - - // TODO: read from the event cache, if available, or fetch from the server. - let res = match room.event(in_reply_to, None).await { + let res = match room.load_or_fetch_event(in_reply_to, None).await { Ok(timeline_event) => TimelineDetails::Ready(Box::new( RepliedToEvent::try_from_timeline_event(timeline_event, room).await?, )), diff --git a/crates/matrix-sdk-ui/src/timeline/mod.rs b/crates/matrix-sdk-ui/src/timeline/mod.rs index 68067a479..78dfdad1a 100644 --- a/crates/matrix-sdk-ui/src/timeline/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/mod.rs @@ -457,8 +457,7 @@ impl Timeline { return timeline_item.replied_to_info(); } - // TODO: read from the event cache, if available, or fetch from the server. - let event = self.room().event(event_id, None).await.map_err(|error| { + let event = self.room().load_or_fetch_event(event_id, None).await.map_err(|error| { error!("Failed to fetch event with ID {event_id} with error: {error}"); UnsupportedReplyItem::MissingEvent })?; diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/replies.rs b/crates/matrix-sdk-ui/tests/integration/timeline/replies.rs index 57aeb15f8..c73ab61d3 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/replies.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/replies.rs @@ -868,11 +868,6 @@ async fn test_send_reply_with_event_id() { .mount() .await; - // Since we assume we can't use the timeline item directly in this use case, the - // API will fetch the event from the server directly so we need to mock the - // response. - server.mock_room_event().ok(bob_event).named("event_1").mock_once().mount().await; - let replied_to_info = timeline.replied_to_info_from_event_id(event_id_from_bob).await.unwrap(); timeline .send_reply( @@ -1148,11 +1143,6 @@ async fn test_send_reply_with_event_id_that_is_redacted() { .mount() .await; - // Since we assume we can't use the timeline item directly in this use case, the - // API will fetch the event from the server directly so we need to mock the - // response. - server.mock_room_event().ok(event_from_bob).mock_once().named("event_1").mount().await; - let replied_to_info = timeline.replied_to_info_from_event_id(redacted_event_id_from_bob).await.unwrap(); timeline