Skip to content

Commit

Permalink
Merge pull request #3177 from matrix-org/doug/multi-user-power-levels
Browse files Browse the repository at this point in the history
FFI: Update the power levels of multiple users at once.
  • Loading branch information
andybalaam authored Mar 4, 2024
2 parents 82684d6 + 370f473 commit 4b711e4
Showing 1 changed file with 21 additions and 6 deletions.
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 @@ -576,15 +576,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 @@ -633,6 +639,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

0 comments on commit 4b711e4

Please sign in to comment.