diff --git a/src/lib.rs b/src/lib.rs index 49244353..e3ddc70a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -398,6 +398,11 @@ where } } +/// Used to default the `bool` fields to `true` during deserialization. +fn default_true() -> bool { + true +} + #[cfg(test)] mod tests { use serde_json::{from_str, to_string}; diff --git a/src/room/create.rs b/src/room/create.rs index 50053588..1180ce48 100644 --- a/src/room/create.rs +++ b/src/room/create.rs @@ -1,8 +1,12 @@ //! Types for the *m.room.create* event. +use std::convert::TryFrom; + use ruma_identifiers::{EventId, RoomId, RoomVersionId, UserId}; use serde::{Deserialize, Serialize}; +use crate::default_true; + state_event! { /// This is the first event in a room and cannot be changed. It acts as the root of all other /// events. @@ -16,11 +20,13 @@ pub struct CreateEventContent { pub creator: UserId, /// Whether or not this room's data should be transferred to other homeservers. #[serde(rename = "m.federate")] - pub federate: Option, + #[serde(default = "default_true")] + pub federate: bool, /// The version of the room. Defaults to "1" if the key does not exist. + #[serde(default = "default_room_version_id")] pub room_version: RoomVersionId, /// A reference to the room this room replaces, if the previous room was upgraded. - pub predecessor: PreviousRoom, + pub predecessor: Option, } /// A reference to an old room replaced during a room version upgrade. @@ -31,3 +37,8 @@ pub struct PreviousRoom { /// The event ID of the last known event in the old room. pub event_id: EventId, } + +/// Used to default the `room_version` field to room version 1. +fn default_room_version_id() -> RoomVersionId { + RoomVersionId::try_from("1").unwrap() +} diff --git a/src/room/power_levels.rs b/src/room/power_levels.rs index 5209b74c..927ea4d0 100644 --- a/src/room/power_levels.rs +++ b/src/room/power_levels.rs @@ -67,6 +67,7 @@ pub struct NotificationPowerLevels { pub room: u64, } +/// Used to default power levels to 50 during deserialization. fn default_power_level() -> u64 { 50 } diff --git a/src/room/server_acl.rs b/src/room/server_acl.rs index e5aa26e0..bcc999c6 100644 --- a/src/room/server_acl.rs +++ b/src/room/server_acl.rs @@ -2,6 +2,8 @@ use serde::{Deserialize, Serialize}; +use crate::default_true; + state_event! { /// An event to indicate which servers are permitted to participate in the room. pub struct ServerAclEvent(ServerAclEventContent) {} @@ -34,11 +36,6 @@ pub struct ServerAclEventContent { pub deny: Vec, } -/// Used to default the `allow_ip_literals` field to `true` during deserialization. -fn default_true() -> bool { - true -} - #[cfg(test)] mod tests { use super::ServerAclEventContent;