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
This commit is contained in:
Jorge Martín
2025-09-16 18:12:07 +02:00
committed by Jorge Martin Espinosa
parent 2166de7b0d
commit 14ca34b09b

View File

@@ -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<TimelineEvent, ClientError> {
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::<AnyTimelineEvent>()?.into())
}
}
/// A thread subscription (MSC4306).