Skip to content

Commit

Permalink
ffi: Expose room heroes on the Room.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Jun 4, 2024
1 parent aba7f63 commit 87f4176
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
28 changes: 27 additions & 1 deletion bindings/matrix-sdk-ffi/src/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::{Context, Result};
use matrix_sdk::{
event_cache::paginator::PaginatorError,
room::{power_levels::RoomPowerLevelChanges, Room as SdkRoom, RoomMemberRole},
RoomMemberships, RoomState,
RoomHero as SdkRoomHero, RoomMemberships, RoomState,
};
use matrix_sdk_ui::timeline::{PaginationError, RoomExt, TimelineFocus};
use mime::Mime;
Expand Down Expand Up @@ -126,6 +126,11 @@ impl Room {
self.inner.state().into()
}

/// Returns the room heroes for this room.
pub fn heroes(&self) -> Vec<RoomHero> {
self.inner.heroes().iter().map(Into::into).collect()
}

/// Is there a non expired membership with application "m.call" and scope
/// "m.room" in this room.
pub fn has_active_room_call(&self) -> bool {
Expand Down Expand Up @@ -780,6 +785,27 @@ impl RoomMembersIterator {
}
}

/// Information about a member considered to be a room hero.
#[derive(uniffi::Record)]
pub struct RoomHero {
/// The user ID of the hero.
user_id: String,
/// The display name of the hero.
display_name: Option<String>,
/// The avatar URL of the hero.
avatar_url: Option<String>,
}

impl From<&SdkRoomHero> for RoomHero {
fn from(value: &SdkRoomHero) -> Self {
Self {
user_id: value.user_id.to_string(),
display_name: value.display_name.clone(),
avatar_url: value.avatar_url.as_ref().map(ToString::to_string),
}
}
}

/// An update for a particular user's power level within the room.
#[derive(uniffi::Record)]
pub struct UserPowerLevelUpdate {
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk-base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ pub use http;
pub use matrix_sdk_crypto as crypto;
pub use once_cell;
pub use rooms::{
DisplayName, Room, RoomCreateWithCreatorEventContent, RoomInfo, RoomInfoUpdate, RoomMember,
RoomMemberships, RoomState, RoomStateFilter,
DisplayName, Room, RoomCreateWithCreatorEventContent, RoomHero, RoomInfo, RoomInfoUpdate,
RoomMember, RoomMemberships, RoomState, RoomStateFilter,
};
pub use store::{StateChanges, StateStore, StateStoreDataKey, StateStoreDataValue, StoreError};
pub use utils::{
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-base/src/rooms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{

use bitflags::bitflags;
pub use members::RoomMember;
pub use normal::{Room, RoomInfo, RoomInfoUpdate, RoomState, RoomStateFilter};
pub use normal::{Room, RoomHero, RoomInfo, RoomInfoUpdate, RoomState, RoomStateFilter};
use ruma::{
assign,
events::{
Expand Down
10 changes: 10 additions & 0 deletions crates/matrix-sdk-base/src/rooms/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,11 @@ impl Room {
Ok(members)
}

/// Get the heroes for this room.
pub fn heroes(&self) -> Vec<RoomHero> {
self.inner.read().heroes().to_owned()
}

/// Get the list of `RoomMember`s that are considered to be joined members
/// of this room.
#[deprecated = "Use members with RoomMemberships::JOIN instead"]
Expand Down Expand Up @@ -1166,6 +1171,11 @@ impl RoomInfo {
self.summary.room_heroes = heroes;
}

/// The heroes for this room.
pub fn heroes(&self) -> &[RoomHero] {
self.summary.room_heroes.deref()
}

/// The number of active members (invited + joined) in the room.
///
/// The return value is saturated at `u64::MAX`.
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub use matrix_sdk_base::crypto;
pub use matrix_sdk_base::{
deserialized_responses,
store::{DynStateStore, MemoryStore, StateStoreExt},
DisplayName, Room as BaseRoom, RoomCreateWithCreatorEventContent, RoomInfo,
DisplayName, Room as BaseRoom, RoomCreateWithCreatorEventContent, RoomHero, RoomInfo,
RoomMember as BaseRoomMember, RoomMemberships, RoomState, SessionMeta, StateChanges,
StateStore, StoreError,
};
Expand Down

0 comments on commit 87f4176

Please sign in to comment.