Move ruma_events::room::power_levels::NotificationPowerLevels to ruma-common
This commit is contained in:
parent
2e422c5d81
commit
cdb998c83f
@ -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;
|
||||
|
26
ruma-common/src/power_levels.rs
Normal file
26
ruma-common/src/power_levels.rs
Normal file
@ -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)
|
||||
}
|
@ -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<PowerLevelsEventContent>;
|
||||
|
||||
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user