Adjust some default values.

This commit is contained in:
Jimmy Cuadra 2019-06-13 16:59:22 -07:00
parent 4661547e21
commit 7530342637
4 changed files with 21 additions and 7 deletions

View File

@ -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};

View File

@ -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<bool>,
#[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<PreviousRoom>,
}
/// 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()
}

View File

@ -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
}

View File

@ -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<String>,
}
/// Used to default the `allow_ip_literals` field to `true` during deserialization.
fn default_true() -> bool {
true
}
#[cfg(test)]
mod tests {
use super::ServerAclEventContent;