Fix deserialization of empty messages

This commit is contained in:
Maybe Waffle 2023-05-01 20:07:52 +04:00
parent 387f6d1284
commit 97247ecbfb
2 changed files with 16 additions and 0 deletions

View file

@ -32,8 +32,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Deserialization of `ApiError::CantParseEntities` ([#839][pr839])
- Deserialization of empty (content-less) messages that can sometimes appear as a part of callback query ([#850][pr850], issue [#873][issue873])
[pr839]: https://github.com/teloxide/teloxide/pull/839
[pr879]: https://github.com/teloxide/teloxide/pull/879
[issue873]: https://github.com/teloxide/teloxide/issues/873
## 0.9.1 - 2023-02-15

View file

@ -78,6 +78,9 @@ pub enum MessageKind {
VideoChatEnded(MessageVideoChatEnded),
VideoChatParticipantsInvited(MessageVideoChatParticipantsInvited),
WebAppData(MessageWebAppData),
/// An empty, content-less message, that can appear in callback queries
/// attached to old messages.
Empty {},
}
#[serde_with_macros::skip_serializing_none]
@ -1446,6 +1449,7 @@ impl Message {
#[cfg(test)]
mod tests {
use cool_asserts::assert_matches;
use serde_json::from_str;
use crate::types::*;
@ -1920,4 +1924,13 @@ mod tests {
let _: Message = serde_json::from_str(json).unwrap();
}
/// Regression test for <https://github.com/teloxide/teloxide/issues/873>
#[test]
fn empty_message() {
let json = r#"{"chat": {"first_name": "FN", "id": 1234567890, "type": "private"}, "date": 0, "message_id": 875400}"#;
let msg: Message = serde_json::from_str(json).unwrap();
assert_matches!(msg.kind, MessageKind::Empty {})
}
}