From 11ef863bf03b43acc2db94b173c50fa34180c73d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= <76261501+zecakeh@users.noreply.github.com> Date: Tue, 22 Mar 2022 12:14:39 +0100 Subject: [PATCH] common: Use Duration in message events --- crates/ruma-common/src/events/room/message.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/ruma-common/src/events/room/message.rs b/crates/ruma-common/src/events/room/message.rs index 36a4f25d..5f9f7d5f 100644 --- a/crates/ruma-common/src/events/room/message.rs +++ b/crates/ruma-common/src/events/room/message.rs @@ -2,7 +2,7 @@ //! //! [`m.room.message`]: https://spec.matrix.org/v1.2/client-server-api/#mroommessage -use std::{borrow::Cow, fmt}; +use std::{borrow::Cow, fmt, time::Duration}; use js_int::UInt; use ruma_macros::EventContent; @@ -510,8 +510,12 @@ impl AudioMessageEventContent { #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct AudioInfo { /// The duration of the audio in milliseconds. - #[serde(skip_serializing_if = "Option::is_none")] - pub duration: Option, + #[serde( + with = "crate::serde::duration::opt_ms", + default, + skip_serializing_if = "Option::is_none" + )] + pub duration: Option, /// The mimetype of the audio, e.g. "audio/aac". #[serde(skip_serializing_if = "Option::is_none")] @@ -1083,8 +1087,12 @@ impl VideoMessageEventContent { #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct VideoInfo { /// The duration of the video in milliseconds. - #[serde(skip_serializing_if = "Option::is_none")] - pub duration: Option, + #[serde( + with = "crate::serde::duration::opt_ms", + default, + skip_serializing_if = "Option::is_none" + )] + pub duration: Option, /// The height of the video in pixels. #[serde(rename = "h", skip_serializing_if = "Option::is_none")]