Skip to content

Commit

Permalink
ffi: Timeline::load_reply_details checks if the event exists locally
Browse files Browse the repository at this point in the history
Before it would go fetch the event from the server using a network request.
  • Loading branch information
jmartinesp committed Jul 4, 2024
1 parent 03d4a30 commit 757190c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
44 changes: 24 additions & 20 deletions bindings/matrix-sdk-ffi/src/timeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -636,23 +639,24 @@ impl Timeline {
) -> Result<InReplyToDetails, ClientError> {
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?;

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(),
},
))
}
let replied_to: Result<RepliedToEvent, Error> = if let Some(event) =
self.inner.item_by_event_id(&event_id).await
{
Ok(RepliedToEvent::from_timeline_item(&event))
} else {
let timeline_event = self.inner.room().event(&event_id).await?;
Ok(RepliedToEvent::try_from_timeline_event_for_room(timeline_event, self.inner.room()))
};

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 757190c

Please sign in to comment.