events: Stabilize deserializing stringified integers for PLs

This commit is contained in:
Kévin Commaille 2022-06-20 17:49:37 +02:00 committed by Kévin Commaille
parent fdb45296c5
commit d729c0f4cd
3 changed files with 40 additions and 70 deletions

View File

@ -30,6 +30,7 @@ Improvements:
* Add `MatrixVersion::V1_3` * Add `MatrixVersion::V1_3`
* Deprecate the `sender_key` and `device_id` fields for encrypted events (MSC3700) * Deprecate the `sender_key` and `device_id` fields for encrypted events (MSC3700)
* Move the `relations` field of `events::unsigned` types out of `unstable-msc2675` * Move the `relations` field of `events::unsigned` types out of `unstable-msc2675`
* Deserialize stringified integers for power levels without the `compat` feature
# 0.9.2 # 0.9.2

View File

@ -22,113 +22,86 @@ use crate::{
#[ruma_event(type = "m.room.power_levels", kind = State, state_key_type = EmptyStateKey)] #[ruma_event(type = "m.room.power_levels", kind = State, state_key_type = EmptyStateKey)]
pub struct RoomPowerLevelsEventContent { pub struct RoomPowerLevelsEventContent {
/// The level required to ban a user. /// The level required to ban a user.
/// #[serde(
/// If you activate the `compat` feature, deserialization will work for stringified default = "default_power_level",
/// integers too. skip_serializing_if = "is_default_power_level",
#[cfg_attr( deserialize_with = "crate::serde::deserialize_v1_powerlevel"
feature = "compat",
serde(deserialize_with = "crate::serde::deserialize_v1_powerlevel")
)] )]
#[serde(default = "default_power_level", skip_serializing_if = "is_default_power_level")]
#[ruma_event(skip_redaction)] #[ruma_event(skip_redaction)]
pub ban: Int, pub ban: Int,
/// The level required to send specific event types. /// The level required to send specific event types.
/// ///
/// This is a mapping from event type to power level required. /// This is a mapping from event type to power level required.
/// #[serde(
/// If you activate the `compat` feature, deserialization will work for stringified default,
/// integers too. skip_serializing_if = "BTreeMap::is_empty",
#[cfg_attr( deserialize_with = "crate::serde::btreemap_deserialize_v1_powerlevel_values"
feature = "compat",
serde(deserialize_with = "crate::serde::btreemap_deserialize_v1_powerlevel_values")
)] )]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
#[ruma_event(skip_redaction)] #[ruma_event(skip_redaction)]
pub events: BTreeMap<RoomEventType, Int>, pub events: BTreeMap<RoomEventType, Int>,
/// The default level required to send message events. /// The default level required to send message events.
/// #[serde(
/// If you activate the `compat` feature, deserialization will work for stringified default,
/// integers too. skip_serializing_if = "crate::serde::is_default",
#[cfg_attr( deserialize_with = "crate::serde::deserialize_v1_powerlevel"
feature = "compat",
serde(deserialize_with = "crate::serde::deserialize_v1_powerlevel")
)] )]
#[serde(default, skip_serializing_if = "crate::serde::is_default")]
#[ruma_event(skip_redaction)] #[ruma_event(skip_redaction)]
pub events_default: Int, pub events_default: Int,
/// The level required to invite a user. /// The level required to invite a user.
/// #[serde(
/// If you activate the `compat` feature, deserialization will work for stringified default,
/// integers too. skip_serializing_if = "crate::serde::is_default",
#[cfg_attr( deserialize_with = "crate::serde::deserialize_v1_powerlevel"
feature = "compat",
serde(deserialize_with = "crate::serde::deserialize_v1_powerlevel")
)] )]
#[serde(default, skip_serializing_if = "crate::serde::is_default")]
pub invite: Int, pub invite: Int,
/// The level required to kick a user. /// The level required to kick a user.
/// #[serde(
/// If you activate the `compat` feature, deserialization will work for stringified default = "default_power_level",
/// integers too. skip_serializing_if = "is_default_power_level",
#[cfg_attr( deserialize_with = "crate::serde::deserialize_v1_powerlevel"
feature = "compat",
serde(deserialize_with = "crate::serde::deserialize_v1_powerlevel")
)] )]
#[serde(default = "default_power_level", skip_serializing_if = "is_default_power_level")]
#[ruma_event(skip_redaction)] #[ruma_event(skip_redaction)]
pub kick: Int, pub kick: Int,
/// The level required to redact an event. /// The level required to redact an event.
/// #[serde(
/// If you activate the `compat` feature, deserialization will work for stringified default = "default_power_level",
/// integers too. skip_serializing_if = "is_default_power_level",
#[cfg_attr( deserialize_with = "crate::serde::deserialize_v1_powerlevel"
feature = "compat",
serde(deserialize_with = "crate::serde::deserialize_v1_powerlevel")
)] )]
#[serde(default = "default_power_level", skip_serializing_if = "is_default_power_level")]
#[ruma_event(skip_redaction)] #[ruma_event(skip_redaction)]
pub redact: Int, pub redact: Int,
/// The default level required to send state events. /// The default level required to send state events.
/// #[serde(
/// If you activate the `compat` feature, deserialization will work for stringified default = "default_power_level",
/// integers too. skip_serializing_if = "is_default_power_level",
#[cfg_attr( deserialize_with = "crate::serde::deserialize_v1_powerlevel"
feature = "compat",
serde(deserialize_with = "crate::serde::deserialize_v1_powerlevel")
)] )]
#[serde(default = "default_power_level", skip_serializing_if = "is_default_power_level")]
#[ruma_event(skip_redaction)] #[ruma_event(skip_redaction)]
pub state_default: Int, pub state_default: Int,
/// The power levels for specific users. /// The power levels for specific users.
/// ///
/// This is a mapping from `user_id` to power level for that user. /// This is a mapping from `user_id` to power level for that user.
/// #[serde(
/// If you activate the `compat` feature, deserialization will work for stringified default,
/// integers too. skip_serializing_if = "BTreeMap::is_empty",
#[cfg_attr( deserialize_with = "crate::serde::btreemap_deserialize_v1_powerlevel_values"
feature = "compat",
serde(deserialize_with = "crate::serde::btreemap_deserialize_v1_powerlevel_values")
)] )]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
#[ruma_event(skip_redaction)] #[ruma_event(skip_redaction)]
pub users: BTreeMap<OwnedUserId, Int>, pub users: BTreeMap<OwnedUserId, Int>,
/// The default power level for every user in the room. /// The default power level for every user in the room.
/// #[serde(
/// If you activate the `compat` feature, deserialization will work for stringified default,
/// integers too. skip_serializing_if = "crate::serde::is_default",
#[cfg_attr( deserialize_with = "crate::serde::deserialize_v1_powerlevel"
feature = "compat",
serde(deserialize_with = "crate::serde::deserialize_v1_powerlevel")
)] )]
#[serde(default, skip_serializing_if = "crate::serde::is_default")]
#[ruma_event(skip_redaction)] #[ruma_event(skip_redaction)]
pub users_default: Int, pub users_default: Int,

View File

@ -10,14 +10,10 @@ use serde::{Deserialize, Serialize};
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct NotificationPowerLevels { pub struct NotificationPowerLevels {
/// The level required to trigger an `@room` notification. /// The level required to trigger an `@room` notification.
/// #[serde(
/// If you activate the `compat` feature, deserialization will work for stringified default = "default_power_level",
/// integers too. deserialize_with = "crate::serde::deserialize_v1_powerlevel"
#[cfg_attr(
feature = "compat",
serde(deserialize_with = "crate::serde::deserialize_v1_powerlevel")
)] )]
#[serde(default = "default_power_level")]
pub room: Int, pub room: Int,
} }