ruma_common/
power_levels.rs1use js_int::{int, Int};
6use ruma_macros::StringEnum;
7use serde::{Deserialize, Serialize};
8
9use crate::PrivOwnedStr;
10
11#[derive(Clone, Debug, Deserialize, Serialize)]
13#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
14pub struct NotificationPowerLevels {
15 #[serde(
19 default = "default_power_level",
20 deserialize_with = "crate::serde::deserialize_v1_powerlevel"
21 )]
22 pub room: Int,
23}
24
25impl NotificationPowerLevels {
26 pub fn new() -> Self {
28 Self { room: default_power_level() }
29 }
30
31 pub fn get(&self, key: &NotificationPowerLevelsKey) -> Option<&Int> {
33 match key {
34 NotificationPowerLevelsKey::Room => Some(&self.room),
35 NotificationPowerLevelsKey::_Custom(_) => None,
36 }
37 }
38
39 pub fn is_default(&self) -> bool {
41 self.room == default_power_level()
42 }
43}
44
45impl Default for NotificationPowerLevels {
46 fn default() -> Self {
47 Self::new()
48 }
49}
50
51pub fn default_power_level() -> Int {
53 int!(50)
54}
55
56#[derive(Clone, PartialEq, Eq, StringEnum)]
58#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
59#[ruma_enum(rename_all = "lowercase")]
60#[non_exhaustive]
61pub enum NotificationPowerLevelsKey {
62 Room,
64
65 #[doc(hidden)]
66 _Custom(PrivOwnedStr),
67}