From f0af335b376adc0c2dddee334e8fac587460c642 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Thu, 10 Oct 2024 12:06:38 +0200 Subject: [PATCH] feat(timeline): add a way to retrieve an `EventTimelineItem` by its unique id --- bindings/matrix-sdk-ffi/src/timeline/mod.rs | 8 ++++++++ crates/matrix-sdk-ui/src/timeline/mod.rs | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/bindings/matrix-sdk-ffi/src/timeline/mod.rs b/bindings/matrix-sdk-ffi/src/timeline/mod.rs index cdbbf0cfc1c..df77a0ee254 100644 --- a/bindings/matrix-sdk-ffi/src/timeline/mod.rs +++ b/bindings/matrix-sdk-ffi/src/timeline/mod.rs @@ -551,6 +551,14 @@ impl Timeline { Ok(()) } + /// Returns a timeline item, given its unique id. + pub async fn event_timeline_item_by_unique_id( + &self, + unique_id: &TimelineUniqueId, + ) -> Option { + self.inner.event_timeline_item_by_unique_id(&unique_id.into()).await.map(Into::into) + } + pub async fn fetch_details_for_event(&self, event_id: String) -> Result<(), ClientError> { let event_id = <&EventId>::try_from(event_id.as_str())?; self.inner.fetch_details_for_event(event_id).await.context("Fetching event details")?; diff --git a/crates/matrix-sdk-ui/src/timeline/mod.rs b/crates/matrix-sdk-ui/src/timeline/mod.rs index 810c6f326d1..aa99fa5398f 100644 --- a/crates/matrix-sdk-ui/src/timeline/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/mod.rs @@ -669,6 +669,15 @@ impl Timeline { Ok(true) } + /// Returns a timeline item, given its unique id. + pub async fn event_timeline_item_by_unique_id( + &self, + unique_id: &TimelineUniqueId, + ) -> Option { + let items = &self.controller.items().await; + rfind_event_by_uid(items, unique_id).map(|(_item_pos, item)| item.inner.clone()) + } + /// Fetch unavailable details about the event with the given ID. /// /// This method only works for IDs of remote [`EventTimelineItem`]s,