events: Add RoomPowerLevels::{for_user, max}
This commit is contained in:
parent
2f32e9863e
commit
d0faeb52f3
@ -2,7 +2,7 @@
|
|||||||
//!
|
//!
|
||||||
//! [`m.room.power_levels`]: https://spec.matrix.org/v1.2/client-server-api/#mroompower_levels
|
//! [`m.room.power_levels`]: https://spec.matrix.org/v1.2/client-server-api/#mroompower_levels
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::{cmp::max, collections::BTreeMap};
|
||||||
|
|
||||||
use js_int::{int, Int};
|
use js_int::{int, Int};
|
||||||
use ruma_macros::EventContent;
|
use ruma_macros::EventContent;
|
||||||
@ -238,6 +238,18 @@ pub struct RoomPowerLevels {
|
|||||||
pub notifications: NotificationPowerLevels,
|
pub notifications: NotificationPowerLevels,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl RoomPowerLevels {
|
||||||
|
/// Get the power level of a specific user.
|
||||||
|
pub fn for_user(&self, user_id: &UserId) -> Int {
|
||||||
|
self.users.get(user_id).map_or(self.users_default, |pl| *pl)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the maximum power level of any user.
|
||||||
|
pub fn max(&self) -> Int {
|
||||||
|
self.users.values().fold(self.users_default, |max_pl, user_pl| max(max_pl, *user_pl))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<RoomPowerLevelsEventContent> for RoomPowerLevels {
|
impl From<RoomPowerLevelsEventContent> for RoomPowerLevels {
|
||||||
fn from(c: RoomPowerLevelsEventContent) -> Self {
|
fn from(c: RoomPowerLevelsEventContent) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user