From 9ce53a2b0269ca711a74c9cd9c79445be215e8fb Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Sat, 25 Dec 2021 04:48:44 +0300 Subject: [PATCH] Fix deserialization of `VoiceChat{Started,Ended}` messages --- CHANGELOG.md | 2 ++ src/types/message.rs | 14 ++++++++++++++ src/types/voice_chat_ended.rs | 2 +- src/types/voice_chat_started.rs | 2 +- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8f3ad5d..6cc47b8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Type of response for `CopyMessage` method ([#141](pr141), [#142](pr142)) - Bad request serialization when the `language` field of `MessageEntityKind::Pre` is `None` ([#145](pr145)) - Deserialization of `MediaKind::Venue` ([#147][pr147]) +- Deserialization of `VoiceChat{Started,Ended}` messages ([#153][pr153]) [pr119]: https://github.com/teloxide/teloxide-core/pull/119 [pr133]: https://github.com/teloxide/teloxide-core/pull/133 @@ -62,6 +63,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [pr143]: https://github.com/teloxide/teloxide-core/pull/143 [pr145]: https://github.com/teloxide/teloxide-core/pull/145 [pr147]: https://github.com/teloxide/teloxide-core/pull/147 +[pr153]: https://github.com/teloxide/teloxide-core/pull/153 [issue473]: https://github.com/teloxide/teloxide/issues/473 [issue427]: https://github.com/teloxide/teloxide/issues/427 diff --git a/src/types/message.rs b/src/types/message.rs index 3da9f02b..cac6e307 100644 --- a/src/types/message.rs +++ b/src/types/message.rs @@ -1393,4 +1393,18 @@ mod tests { } ) } + + /// Regression test for + #[test] + fn issue_475() { + let json = r#"{"message_id":198295,"from":{"id":1087968824,"is_bot":true,"first_name":"Group","username":"GroupAnonymousBot"},"sender_chat":{"id":-1001331354980,"title":"C++ Together 2.0","username":"cpptogether","type":"supergroup"},"chat":{"id":-1001331354980,"title":"C++ Together 2.0","username":"cpptogether","type":"supergroup"},"date":1638236631,"voice_chat_started":{}}"#; + + let message: Message = serde_json::from_str(json).unwrap(); + + assert!(matches!(message.kind, MessageKind::VoiceChatStarted { .. })); + + // FIXME(waffle): it seems like we are losing `sender_chat` in some + // cases inclusing this + // assert!(message.sender_chat().is_some()); + } } diff --git a/src/types/voice_chat_ended.rs b/src/types/voice_chat_ended.rs index 8ca83332..1c8ef3d6 100644 --- a/src/types/voice_chat_ended.rs +++ b/src/types/voice_chat_ended.rs @@ -3,4 +3,4 @@ use serde::{Deserialize, Serialize}; /// This object represents a service message about a voice chat ended in the /// chat. #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] -pub struct VoiceChatEnded; +pub struct VoiceChatEnded {} diff --git a/src/types/voice_chat_started.rs b/src/types/voice_chat_started.rs index 82bb2f30..1aeec86f 100644 --- a/src/types/voice_chat_started.rs +++ b/src/types/voice_chat_started.rs @@ -3,4 +3,4 @@ use serde::{Deserialize, Serialize}; /// This object represents a service message about a voice chat started in the /// chat. Currently holds no information. #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] -pub struct VoiceChatStarted; +pub struct VoiceChatStarted {}