From 769128287e6f9ab4428934aa68d101ee23c0dbdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=8B=D1=80=D1=86=D0=B5=D0=B2=20=D0=92=D0=B0=D0=B4?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=98=D0=B3=D0=BE=D1=80=D0=B5=D0=B2=D0=B8=D1=87?= Date: Thu, 11 Jul 2024 17:34:45 +0300 Subject: [PATCH] Fix serde support for some types from TBA 6.8 --- .../teloxide-core/src/types/chat_full_info.rs | 27 +++++++++++++++++-- crates/teloxide-core/src/types/story.rs | 2 +- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/crates/teloxide-core/src/types/chat_full_info.rs b/crates/teloxide-core/src/types/chat_full_info.rs index 3f5bc70c..9857ce7d 100644 --- a/crates/teloxide-core/src/types/chat_full_info.rs +++ b/crates/teloxide-core/src/types/chat_full_info.rs @@ -1,3 +1,4 @@ +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; // TODO: in the TBA7.3 the Chat will be splitted into Chat and ChatInfo @@ -5,8 +6,30 @@ use serde::{Deserialize, Serialize}; #[serde_with_macros::skip_serializing_none] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct ChatFullInfo { - // FIXME: better type for the unix timestamp? /// Expiration date of the emoji status of the chat or the other party in a /// private chat, in Unix time, if any - pub emoji_status_expiration_date: Option, + #[serde(default, with = "crate::types::serde_opt_date_from_unix_timestamp")] + pub emoji_status_expiration_date: Option>, +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_chat_full_info_de() { + assert_eq!( + serde_json::from_str::("{}").unwrap(), + ChatFullInfo { emoji_status_expiration_date: None } + ); + assert_eq!( + serde_json::from_str::( + r#"{ + "emoji_status_expiration_date": 1720708004 + }"# + ) + .unwrap(), + ChatFullInfo { emoji_status_expiration_date: DateTime::from_timestamp(1720708004, 0) } + ); + } } diff --git a/crates/teloxide-core/src/types/story.rs b/crates/teloxide-core/src/types/story.rs index 86c84094..a59e1568 100644 --- a/crates/teloxide-core/src/types/story.rs +++ b/crates/teloxide-core/src/types/story.rs @@ -2,4 +2,4 @@ use serde::{Deserialize, Serialize}; /// TBA 6.8: currently it holds no information #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] -pub struct Story; +pub struct Story {}