Skip to content

Commit 1f08885

Browse files
committed
fixup! chore(room_preview): Add knocking action to the RoomPreviewActions too
1 parent 69ee5c2 commit 1f08885

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

bindings/matrix-sdk-ffi/src/client.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ impl Client {
10271027
&self,
10281028
room_id: String,
10291029
via_servers: Vec<String>,
1030-
) -> Result<RoomPreview, ClientError> {
1030+
) -> Result<Arc<RoomPreview>, ClientError> {
10311031
let room_id = RoomId::parse(&room_id).context("room_id is not a valid room id")?;
10321032

10331033
let via_servers = via_servers
@@ -1042,14 +1042,14 @@ impl Client {
10421042

10431043
let sdk_room_preview = self.inner.get_room_preview(room_id.into(), via_servers).await?;
10441044

1045-
Ok(RoomPreview::from_sdk(sdk_room_preview))
1045+
Ok(Arc::new(RoomPreview::from_sdk(sdk_room_preview)))
10461046
}
10471047

10481048
/// Given a room alias, get the preview of a room, to interact with it.
10491049
pub async fn get_room_preview_from_room_alias(
10501050
&self,
10511051
room_alias: String,
1052-
) -> Result<RoomPreview, ClientError> {
1052+
) -> Result<Arc<RoomPreview>, ClientError> {
10531053
let room_alias =
10541054
RoomAliasId::parse(&room_alias).context("room_alias is not a valid room alias")?;
10551055

@@ -1059,7 +1059,7 @@ impl Client {
10591059

10601060
let sdk_room_preview = self.inner.get_room_preview(room_alias.into(), Vec::new()).await?;
10611061

1062-
Ok(RoomPreview::from_sdk(sdk_room_preview))
1062+
Ok(Arc::new(RoomPreview::from_sdk(sdk_room_preview)))
10631063
}
10641064

10651065
/// Waits until an at least partially synced room is received, and returns

bindings/matrix-sdk-ffi/src/room_list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ impl RoomListItem {
598598
///
599599
/// An error will be returned if the room is in a state other than invited
600600
/// or knocked.
601-
async fn preview_room(&self, via: Vec<String>) -> Result<RoomPreview, ClientError> {
601+
async fn preview_room(&self, via: Vec<String>) -> Result<Arc<RoomPreview>, ClientError> {
602602
let membership = self.membership();
603603
if !matches!(membership, Membership::Invited | Membership::Knocked) {
604604
return Err(RoomListError::IncorrectRoomMembership {
@@ -622,7 +622,7 @@ impl RoomListItem {
622622
};
623623

624624
let room_preview = client.get_room_preview(&room_or_alias_id, server_names).await?;
625-
Ok(RoomPreview::from_sdk(room_preview))
625+
Ok(Arc::new(RoomPreview::from_sdk(room_preview)))
626626
}
627627

628628
/// Build a full `Room` FFI object, filling its associated timeline.

bindings/matrix-sdk-ffi/src/room_preview.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::sync::Arc;
12
use matrix_sdk::room_preview::RoomPreview as SdkRoomPreview;
23
use ruma::space::SpaceRoomJoinRule;
34

@@ -7,25 +8,25 @@ use crate::{client::JoinRule, error::ClientError, room::Membership};
78
/// aren't joined yet.
89
#[derive(uniffi::Object)]
910
pub struct RoomPreview {
10-
inner: SdkRoomPreview,
11+
inner: Arc<SdkRoomPreview>,
1112
}
1213

1314
#[matrix_sdk_ffi_macros::export]
1415
impl RoomPreview {
1516
/// Returns the room info the preview contains.
1617
pub fn info(&self) -> RoomPreviewInfo {
17-
let info = self.inner.clone();
18+
let info = &self.inner;
1819
RoomPreviewInfo {
1920
room_id: info.room_id.to_string(),
20-
canonical_alias: info.canonical_alias.map(|alias| alias.to_string()),
21-
name: info.name,
22-
topic: info.topic,
23-
avatar_url: info.avatar_url.map(|url| url.to_string()),
21+
canonical_alias: info.canonical_alias.as_ref().map(|alias| alias.to_string()),
22+
name: info.name.clone(),
23+
topic: info.topic.clone(),
24+
avatar_url: info.avatar_url.as_ref().map(|url| url.to_string()),
2425
num_joined_members: info.num_joined_members,
25-
room_type: info.room_type.map(|room_type| room_type.to_string()),
26+
room_type: info.room_type.as_ref().map(|room_type| room_type.to_string()),
2627
is_history_world_readable: info.is_world_readable,
2728
membership: info.state.map(|state| state.into()),
28-
join_rule: info.join_rule.into(),
29+
join_rule: info.join_rule.clone().into(),
2930
}
3031
}
3132

@@ -40,7 +41,7 @@ impl RoomPreview {
4041

4142
impl RoomPreview {
4243
pub(crate) fn from_sdk(room_preview: SdkRoomPreview) -> Self {
43-
Self { inner: room_preview }
44+
Self { inner: Arc::new(room_preview) }
4445
}
4546
}
4647

0 commit comments

Comments
 (0)