Skip to content

Commit

Permalink
feat(ffi): add RoomPreviewInfo::num_active_members
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinesp committed Nov 14, 2024
1 parent bf4a2ed commit 9795290
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions bindings/matrix-sdk-ffi/src/room_preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -77,6 +78,8 @@ pub struct RoomPreviewInfo {
pub avatar_url: Option<String>,
/// The number of joined members.
pub num_joined_members: u64,
/// The number of active members, if known (joined + invited).
pub num_active_members: Option<u64>,
/// The room type (space, custom) or nothing, if it's a regular room.
pub room_type: Option<String>,
/// Is the history world-readable for this room?
Expand Down
18 changes: 17 additions & 1 deletion crates/matrix-sdk/src/room_preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>,

/// The room type (space, custom) or nothing, if it's a regular room.
pub room_type: Option<RoomType>,

Expand Down Expand Up @@ -83,6 +86,7 @@ impl RoomPreview {
room_info: RoomInfo,
is_direct: Option<bool>,
num_joined_members: u64,
num_active_members: Option<u64>,
state: Option<RoomState>,
) -> Self {
RoomPreview {
Expand All @@ -107,6 +111,7 @@ impl RoomPreview {
},
is_world_readable: *room_info.history_visibility() == HistoryVisibility::WorldReadable,
num_joined_members,
num_active_members,
state,
is_direct,
}
Expand All @@ -121,6 +126,7 @@ impl RoomPreview {
room.clone_info(),
is_direct,
room.joined_members_count(),
Some(room.active_members_count()),
Some(room.state()),
)
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
))
}
}

0 comments on commit 9795290

Please sign in to comment.