From cdb998c83fde78d75296d6bf0482c1c6378d4beb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Wed, 24 Mar 2021 16:52:05 +0100 Subject: [PATCH] Move ruma_events::room::power_levels::NotificationPowerLevels to ruma-common --- ruma-common/src/lib.rs | 1 + ruma-common/src/power_levels.rs | 26 ++++++++++++++++++++++++++ ruma-events/src/room/power_levels.rs | 23 +++-------------------- 3 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 ruma-common/src/power_levels.rs diff --git a/ruma-common/src/lib.rs b/ruma-common/src/lib.rs index 6f4f373f..fbfe69df 100644 --- a/ruma-common/src/lib.rs +++ b/ruma-common/src/lib.rs @@ -5,6 +5,7 @@ pub mod authentication; pub mod directory; pub mod encryption; +pub mod power_levels; pub mod presence; pub mod push; pub mod thirdparty; diff --git a/ruma-common/src/power_levels.rs b/ruma-common/src/power_levels.rs new file mode 100644 index 00000000..07d04dc8 --- /dev/null +++ b/ruma-common/src/power_levels.rs @@ -0,0 +1,26 @@ +//! Common types for the [`m.room.power_levels` event][power_levels] +//! +//! [power_levels]: https://matrix.org/docs/spec/client_server/r0.6.1#m-room-power-levels + +use js_int::Int; +use serde::{Deserialize, Serialize}; + +/// The power level requirements for specific notification types. +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] +pub struct NotificationPowerLevels { + /// The level required to trigger an `@room` notification. + #[cfg_attr(feature = "compat", serde(deserialize_with = "ruma_serde::int_or_string_to_int"))] + #[serde(default = "default_power_level")] + pub room: Int, +} + +impl Default for NotificationPowerLevels { + fn default() -> Self { + Self { room: default_power_level() } + } +} + +/// Used to default power levels to 50 during deserialization. +pub fn default_power_level() -> Int { + Int::from(50) +} diff --git a/ruma-events/src/room/power_levels.rs b/ruma-events/src/room/power_levels.rs index 593ff01c..607a804f 100644 --- a/ruma-events/src/room/power_levels.rs +++ b/ruma-events/src/room/power_levels.rs @@ -3,12 +3,15 @@ use std::collections::BTreeMap; use js_int::Int; +use ruma_common::power_levels::default_power_level; use ruma_events_macros::StateEventContent; use ruma_identifiers::UserId; use serde::{Deserialize, Serialize}; use crate::{EventType, StateEvent}; +pub use ruma_common::power_levels::NotificationPowerLevels; + /// Defines the power levels (privileges) of users in the room. pub type PowerLevelsEvent = StateEvent; @@ -105,26 +108,6 @@ impl Default for PowerLevelsEventContent { } } -/// The power level requirements for specific notification types. -#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] -pub struct NotificationPowerLevels { - /// The level required to trigger an `@room` notification. - #[cfg_attr(feature = "compat", serde(deserialize_with = "ruma_serde::int_or_string_to_int"))] - #[serde(default = "default_power_level")] - pub room: Int, -} - -impl Default for NotificationPowerLevels { - fn default() -> Self { - Self { room: default_power_level() } - } -} - -/// Used to default power levels to 50 during deserialization. -fn default_power_level() -> Int { - Int::from(50) -} - /// Used with `#[serde(skip_serializing_if)]` to omit default power levels. #[allow(clippy::trivially_copy_pass_by_ref)] fn is_default_power_level(l: &Int) -> bool {