From 07b6425e10dd3183a8ef4399ca954aa8a422eabb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Mart=C3=ADn?= Date: Thu, 4 Jul 2024 13:48:17 +0200 Subject: [PATCH] ffi: Timeline::load_reply_details checks if the event exists locally Before it would go fetch the event from the server using a network request. --- bindings/matrix-sdk-ffi/src/timeline/mod.rs | 47 +++++++++++-------- .../timeline/event_item/content/message.rs | 2 +- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/timeline/mod.rs b/bindings/matrix-sdk-ffi/src/timeline/mod.rs index ad9170b9f..bf24f3454 100644 --- a/bindings/matrix-sdk-ffi/src/timeline/mod.rs +++ b/bindings/matrix-sdk-ffi/src/timeline/mod.rs @@ -19,9 +19,12 @@ use as_variant::as_variant; use content::{InReplyToDetails, RepliedToEventDetails}; use eyeball_im::VectorDiff; use futures_util::{pin_mut, StreamExt as _}; -use matrix_sdk::attachment::{ - AttachmentConfig, AttachmentInfo, BaseAudioInfo, BaseFileInfo, BaseImageInfo, - BaseThumbnailInfo, BaseVideoInfo, Thumbnail, +use matrix_sdk::{ + attachment::{ + AttachmentConfig, AttachmentInfo, BaseAudioInfo, BaseFileInfo, BaseImageInfo, + BaseThumbnailInfo, BaseVideoInfo, Thumbnail, + }, + Error, }; use matrix_sdk_ui::timeline::{ EventItemOrigin, LiveBackPaginationStatus, Profile, RepliedToEvent, TimelineDetails, @@ -636,23 +639,29 @@ impl Timeline { ) -> Result { let event_id = EventId::parse(&event_id_str)?; - match self.inner.room().event(&event_id).await { - Ok(timeline_event) => { - let replied_to = RepliedToEvent::try_from_timeline_event_for_room( - timeline_event, - self.inner.room(), - ) - .await?; + let replied_to: Result = + if let Some(event) = self.inner.item_by_event_id(&event_id).await { + Ok(RepliedToEvent::from_timeline_item(&event)) + } else { + match self.inner.room().event(&event_id).await { + Ok(timeline_event) => Ok(RepliedToEvent::try_from_timeline_event_for_room( + timeline_event, + self.inner.room(), + ) + .await?), + Err(e) => Err(e), + } + }; - Ok(InReplyToDetails::new( - event_id_str, - RepliedToEventDetails::Ready { - content: Arc::new(TimelineItemContent(replied_to.content().clone())), - sender: replied_to.sender().to_string(), - sender_profile: replied_to.sender_profile().into(), - }, - )) - } + match replied_to { + Ok(replied_to) => Ok(InReplyToDetails::new( + event_id_str, + RepliedToEventDetails::Ready { + content: Arc::new(TimelineItemContent(replied_to.content().clone())), + sender: replied_to.sender().to_string(), + sender_profile: replied_to.sender_profile().into(), + }, + )), Err(e) => Ok(InReplyToDetails::new( event_id_str, diff --git a/crates/matrix-sdk-ui/src/timeline/event_item/content/message.rs b/crates/matrix-sdk-ui/src/timeline/event_item/content/message.rs index 28e217a2b..808204210 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_item/content/message.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_item/content/message.rs @@ -263,7 +263,7 @@ impl RepliedToEvent { &self.sender_profile } - pub(crate) fn from_timeline_item(timeline_item: &EventTimelineItem) -> Self { + pub fn from_timeline_item(timeline_item: &EventTimelineItem) -> Self { Self { content: timeline_item.content.clone(), sender: timeline_item.sender.clone(),