Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ffi: Timeline::load_reply_details checks if the event exists locally #3656

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions bindings/matrix-sdk-ffi/src/timeline/mod.rs
Original file line number Diff line number Diff line change
@@ -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<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 {
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),
}
};

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