From 4a91932ea8492195405dc3d488869c440e9f9c76 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 3 Aug 2017 22:10:11 +0200 Subject: [PATCH] Fix a bunch more deserialization bugs --- src/call/candidates.rs | 2 ++ src/call/mod.rs | 1 + src/presence.rs | 1 + src/receipt.rs | 1 + src/room/avatar.rs | 9 ++++++--- src/room/mod.rs | 4 ++-- src/stripped.rs | 20 +++++++++++--------- 7 files changed, 24 insertions(+), 14 deletions(-) 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/mod.rs b/src/room/mod.rs index 95b5a186..b4f73d11 100644 --- a/src/room/mod.rs +++ b/src/room/mod.rs @@ -21,11 +21,11 @@ pub mod topic; #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] pub struct ImageInfo { /// The height of the image in pixels. - pub height: u64, + pub h: 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. - pub width: u64, + pub w: u64, } diff --git a/src/stripped.rs b/src/stripped.rs index 04ed37e4..a760e456 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.h, 128); + assert_eq!(image_info.w, 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, "");