From 14ca34b09bd8a29214cf0a7b8a69fe2491beaef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Mart=C3=ADn?= Date: Tue, 16 Sep 2025 18:12:07 +0200 Subject: [PATCH] feat(ffi): Add `Room::load_or_fetch_event` to the FFI layer This way we can retrieve random events in a room and check their properties - this is needed to decide whether a permalink for an event should open in a thread or not --- bindings/matrix-sdk-ffi/src/room/mod.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bindings/matrix-sdk-ffi/src/room/mod.rs b/bindings/matrix-sdk-ffi/src/room/mod.rs index f5d0da98a..ca79ef9bb 100644 --- a/bindings/matrix-sdk-ffi/src/room/mod.rs +++ b/bindings/matrix-sdk-ffi/src/room/mod.rs @@ -27,7 +27,7 @@ use ruma::{ join_rules::JoinRule as RumaJoinRule, message::RoomMessageEventContentWithoutRelation, MediaSource, }, - AnyMessageLikeEventContent, AnySyncTimelineEvent, + AnyMessageLikeEventContent, AnySyncTimelineEvent, AnyTimelineEvent, }, EventId, Int, OwnedDeviceId, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId, RoomAliasId, ServerName, UserId, @@ -39,6 +39,7 @@ use crate::{ chunk_iterator::ChunkIterator, client::{JoinRule, RoomVisibility}, error::{ClientError, MediaInfoError, NotYetImplemented, RoomError}, + event::TimelineEvent, identity_status_change::IdentityStatusChange, live_location_share::{LastLocation, LiveLocationShare}, room_member::{RoomMember, RoomMemberWithSenderInfo}, @@ -1178,6 +1179,17 @@ impl Room { .await? .map(|sub| ThreadSubscription { automatic: sub.automatic })) } + + /// Either loads the event associated with the `event_id` from the event + /// cache or fetches it from the homeserver. + pub async fn load_or_fetch_event( + &self, + event_id: String, + ) -> Result { + let event_id = EventId::parse(event_id)?; + let timeline_event = self.inner.load_or_fetch_event(&event_id, None).await?; + Ok(timeline_event.kind.into_raw().deserialize_as_unchecked::()?.into()) + } } /// A thread subscription (MSC4306).