Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFI: Update the power levels of multiple users at once. #3177

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions bindings/matrix-sdk-ffi/src/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,15 +581,21 @@ impl Room {
Ok(())
}

pub async fn update_power_level_for_user(
pub async fn update_power_levels_for_users(
&self,
user_id: String,
power_level: i64,
updates: Vec<UserPowerLevelUpdate>,
) -> Result<(), ClientError> {
let user_id = UserId::parse(&user_id)?;
let power_level = Int::new(power_level).context("Invalid power level")?;
let updates = updates
.iter()
.map(|update| {
let user_id: &UserId = update.user_id.as_str().try_into()?;
let power_level = Int::new(update.power_level).context("Invalid power level")?;
Ok((user_id, power_level))
})
.collect::<Result<Vec<_>>>()?;

self.inner
.update_power_levels(vec![(&user_id, power_level)])
.update_power_levels(updates)
.await
.map_err(|e| ClientError::Generic { msg: e.to_string() })?;
Ok(())
Expand Down Expand Up @@ -638,6 +644,15 @@ impl RoomMembersIterator {
}
}

/// An update for a particular user's power level within the room.
#[derive(uniffi::Record)]
pub struct UserPowerLevelUpdate {
/// The user ID of the user to update.
user_id: String,
/// The power level to assign to the user.
power_level: i64,
}

impl TryFrom<ImageInfo> for RumaAvatarImageInfo {
type Error = MediaInfoError;

Expand Down
Loading