diff --git a/bindings/matrix-sdk-ffi/src/room_preview.rs b/bindings/matrix-sdk-ffi/src/room_preview.rs index 14237d2544f..5de8e5981c9 100644 --- a/bindings/matrix-sdk-ffi/src/room_preview.rs +++ b/bindings/matrix-sdk-ffi/src/room_preview.rs @@ -27,6 +27,7 @@ impl RoomPreview { avatar_url: info.avatar_url.as_ref().map(|url| url.to_string()), num_joined_members: info.num_joined_members, room_type: info.room_type.as_ref().map(|room_type| room_type.to_string()), + num_active_members: info.num_active_members, is_history_world_readable: info.is_world_readable, membership: info.state.map(|state| state.into()), join_rule: info @@ -77,6 +78,8 @@ pub struct RoomPreviewInfo { pub avatar_url: Option, /// The number of joined members. pub num_joined_members: u64, + /// The number of active members, if known (joined + invited). + pub num_active_members: Option, /// The room type (space, custom) or nothing, if it's a regular room. pub room_type: Option, /// Is the history world-readable for this room? diff --git a/crates/matrix-sdk/src/room_preview.rs b/crates/matrix-sdk/src/room_preview.rs index c102b6225ff..3cccf952ea3 100644 --- a/crates/matrix-sdk/src/room_preview.rs +++ b/crates/matrix-sdk/src/room_preview.rs @@ -55,6 +55,9 @@ pub struct RoomPreview { /// The number of joined members. pub num_joined_members: u64, + /// The number of active members, if known (joined + invited). + pub num_active_members: Option, + /// The room type (space, custom) or nothing, if it's a regular room. pub room_type: Option, @@ -83,6 +86,7 @@ impl RoomPreview { room_info: RoomInfo, is_direct: Option, num_joined_members: u64, + num_active_members: Option, state: Option, ) -> Self { RoomPreview { @@ -107,6 +111,7 @@ impl RoomPreview { }, is_world_readable: *room_info.history_visibility() == HistoryVisibility::WorldReadable, num_joined_members, + num_active_members, state, is_direct, } @@ -121,6 +126,7 @@ impl RoomPreview { room.clone_info(), is_direct, room.joined_members_count(), + Some(room.active_members_count()), Some(room.state()), ) } @@ -178,6 +184,8 @@ impl RoomPreview { response.membership.map(|membership| RoomState::from(&membership)) }; + let num_active_members = cached_room.as_ref().map(|r| r.active_members_count()); + let is_direct = if let Some(cached_room) = cached_room { cached_room.is_direct().await.ok() } else { @@ -191,6 +199,7 @@ impl RoomPreview { topic: response.topic, avatar_url: response.avatar_url, num_joined_members: response.num_joined_members.into(), + num_active_members, room_type: response.room_type, join_rule: response.join_rule, is_world_readable: response.world_readable, @@ -238,8 +247,15 @@ impl RoomPreview { let room = client.get_room(room_id); let state = room.as_ref().map(|room| room.state()); + let num_active_members = room.as_ref().map(|r| r.active_members_count()); let is_direct = if let Some(room) = room { room.is_direct().await.ok() } else { None }; - Ok(Self::from_room_info(room_info, is_direct, num_joined_members, state)) + Ok(Self::from_room_info( + room_info, + is_direct, + num_joined_members, + num_active_members, + state, + )) } }