diff --git a/src/call/candidates.rs b/src/call/candidates.rs index a9642073..352ca046 100644 --- a/src/call/candidates.rs +++ b/src/call/candidates.rs @@ -24,7 +24,9 @@ pub struct Candidate { /// The SDP "a" line of the candidate. pub candidate: String, /// The SDP media type this candidate is intended for. + #[serde(rename = "sdpMid")] pub sdp_mid: String, /// The index of the SDP "m" line this candidate is intended for. + #[serde(rename = "sdpMLineIndex")] pub sdp_m_line_index: u64, } diff --git a/src/call/mod.rs b/src/call/mod.rs index d94786fe..6097f86f 100644 --- a/src/call/mod.rs +++ b/src/call/mod.rs @@ -11,6 +11,7 @@ pub mod invite; #[derive(Clone, Debug, Deserialize, Serialize)] pub struct SessionDescription { /// The type of session description. + #[serde(rename="type")] pub session_type: SessionDescriptionType, /// The SDP text of the session description. pub sdp: String, diff --git a/src/presence.rs b/src/presence.rs index e86ee38c..5ed4001f 100644 --- a/src/presence.rs +++ b/src/presence.rs @@ -18,6 +18,7 @@ pub struct PresenceEventContent { pub avatar_url: Option, /// Whether or not the user is currently active. + #[serde(skip_serializing_if="Option::is_none")] pub currently_active: Option, /// The current display name for this user. diff --git a/src/receipt.rs b/src/receipt.rs index 42b6cabe..2d5b08cc 100644 --- a/src/receipt.rs +++ b/src/receipt.rs @@ -23,6 +23,7 @@ pub type ReceiptEventContent = HashMap; pub struct Receipts { /// A collection of users who have sent *m.read* receipts for this event. #[serde(rename="m.read")] + #[serde(default)] pub m_read: UserReceipts, } diff --git a/src/room/avatar.rs b/src/room/avatar.rs index d900fdbf..741a0f36 100644 --- a/src/room/avatar.rs +++ b/src/room/avatar.rs @@ -13,11 +13,14 @@ state_event! { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct AvatarEventContent { /// Information about the avatar image. - pub info: ImageInfo, + #[serde(skip_serializing_if="Option::is_none")] + pub info: Option, /// Information about the avatar thumbnail image. - pub thumbnail_info: ImageInfo, + #[serde(skip_serializing_if="Option::is_none")] + pub thumbnail_info: Option, /// URL of the avatar thumbnail image. - pub thumbnail_url: String, + #[serde(skip_serializing_if="Option::is_none")] + pub thumbnail_url: Option, /// URL of the avatar image. pub url: String, } diff --git a/src/room/message.rs b/src/room/message.rs index 32d50631..487ff2f3 100644 --- a/src/room/message.rs +++ b/src/room/message.rs @@ -56,22 +56,22 @@ pub enum MessageEventContent { /// An emote message. Emote(EmoteMessageEventContent), - /// An file message. + /// A file message. File(FileMessageEventContent), /// An image message. Image(ImageMessageEventContent), - /// An location message. + /// A location message. Location(LocationMessageEventContent), - /// An notice message. + /// A notice message. Notice(NoticeMessageEventContent), /// An text message. Text(TextMessageEventContent), - /// An video message. + /// A video message. Video(VideoMessageEventContent), } @@ -221,8 +221,9 @@ pub struct VideoInfo { #[serde(skip_serializing_if="Option::is_none")] pub duration: Option, /// The height of the video in pixels. + #[serde(rename = "h")] #[serde(skip_serializing_if="Option::is_none")] - pub h: Option, + pub height: Option, /// The mimetype of the video, e.g. "video/mp4." #[serde(skip_serializing_if="Option::is_none")] pub mimetype: Option, @@ -236,8 +237,9 @@ pub struct VideoInfo { #[serde(skip_serializing_if="Option::is_none")] pub thumbnail_url: Option, /// The width of the video in pixels. + #[serde(rename = "w")] #[serde(skip_serializing_if="Option::is_none")] - pub w: Option, + pub width: Option, } impl_enum! { diff --git a/src/room/mod.rs b/src/room/mod.rs index 95b5a186..232f7556 100644 --- a/src/room/mod.rs +++ b/src/room/mod.rs @@ -21,11 +21,13 @@ pub mod topic; #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] pub struct ImageInfo { /// The height of the image in pixels. + #[serde(rename = "h")] pub height: u64, /// The MIME type of the image, e.g. "image/png." pub mimetype: String, /// The file size of the image in bytes. pub size: u64, /// The width of the image in pixels. + #[serde(rename = "w")] pub width: u64, } diff --git a/src/stripped.rs b/src/stripped.rs index 04ed37e4..28d50500 100644 --- a/src/stripped.rs +++ b/src/stripped.rs @@ -291,14 +291,14 @@ mod tests { "state_key": "", "content": { "info": { - "height": 128, - "width": 128, + "h": 128, + "w": 128, "mimetype": "image/jpeg", "size": 1024 }, "thumbnail_info": { - "height": 16, - "width": 16, + "h": 16, + "w": 16, "mimetype": "image/jpeg", "size": 32 }, @@ -331,11 +331,13 @@ mod tests { match from_str::(avatar_event).unwrap() { StrippedState::RoomAvatar(event) => { - assert_eq!(event.content.info.height, 128); - assert_eq!(event.content.info.width, 128); - assert_eq!(event.content.info.mimetype, "image/jpeg"); - assert_eq!(event.content.info.size, 1024); - assert_eq!(event.content.thumbnail_info.size, 32); + let image_info = event.content.info.unwrap(); + + assert_eq!(image_info.height, 128); + assert_eq!(image_info.width, 128); + assert_eq!(image_info.mimetype, "image/jpeg"); + assert_eq!(image_info.size, 1024); + assert_eq!(event.content.thumbnail_info.unwrap().size, 32); assert_eq!(event.content.url, "https://domain.com/image.jpg"); assert_eq!(event.event_type, EventType::RoomAvatar); assert_eq!(event.state_key, "");