Merge pull request #879 from teloxide/empty_message

Fix deserialization of empty messages
This commit is contained in:
Waffle Maybe 2023-05-23 21:04:21 +00:00 committed by GitHub
commit b7c1cd9494
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View file

@ -56,8 +56,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 {})
}
}