Message struct skip serializing for none fields

This commit is contained in:
Oleg A 2023-03-18 18:35:53 +03:00
parent da00c9274b
commit 4d0fc03fa2
No known key found for this signature in database
GPG key ID: 5FE046817A9657C5

View file

@ -17,6 +17,7 @@ use crate::types::{
/// This object represents a message.
///
/// [The official docs](https://core.telegram.org/bots/api#message).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Message {
/// Unique message identifier inside this chat.
@ -132,6 +133,7 @@ pub struct MessageCommon {
pub has_protected_content: bool,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageNewChatMembers {
/// New members that were added to the group or supergroup and
@ -140,6 +142,7 @@ pub struct MessageNewChatMembers {
pub new_chat_members: Vec<User>,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageLeftChatMember {
/// A member was removed from the group, information about them (this
@ -147,30 +150,35 @@ pub struct MessageLeftChatMember {
pub left_chat_member: User,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageNewChatTitle {
/// A chat title was changed to this value.
pub new_chat_title: String,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageNewChatPhoto {
/// A chat photo was change to this value.
pub new_chat_photo: Vec<PhotoSize>,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct MessageDeleteChatPhoto {
/// Service message: the chat photo was deleted.
pub delete_chat_photo: True,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct MessageGroupChatCreated {
/// Service message: the group has been created.
pub group_chat_created: True,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct MessageSupergroupChatCreated {
/// Service message: the supergroup has been created. This field cant
@ -181,6 +189,7 @@ pub struct MessageSupergroupChatCreated {
pub supergroup_chat_created: True,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct MessageChannelChatCreated {
/// Service message: the channel has been created. This field cant be
@ -191,6 +200,7 @@ pub struct MessageChannelChatCreated {
pub channel_chat_created: True,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageMessageAutoDeleteTimerChanged {
/// Service message: auto-delete timer settings changed in the chat.
@ -225,6 +235,7 @@ pub enum ChatMigration {
},
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessagePinned {
/// Specified message was pinned. Note that the Message object in this
@ -234,6 +245,7 @@ pub struct MessagePinned {
pub pinned: Box<Message>,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageInvoice {
/// Message is an invoice for a [payment], information about the
@ -244,6 +256,7 @@ pub struct MessageInvoice {
pub invoice: Invoice,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageSuccessfulPayment {
/// Message is a service message about a successful payment,
@ -253,6 +266,7 @@ pub struct MessageSuccessfulPayment {
pub successful_payment: SuccessfulPayment,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageConnectedWebsite {
/// The domain name of the website on which the user has logged in.
@ -262,6 +276,7 @@ pub struct MessageConnectedWebsite {
pub connected_website: String,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessagePassportData {
/// Telegram Passport data.
@ -269,6 +284,7 @@ pub struct MessagePassportData {
}
/// Information about forwarded message.
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Forward {
/// Date the original message was sent in Unix time.
@ -336,6 +352,7 @@ pub enum MediaKind {
Migration(ChatMigration),
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MediaAnimation {
/// Message is an animation, information about the animation. For
@ -376,6 +393,7 @@ pub struct MediaAudio {
pub media_group_id: Option<String>,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MediaContact {
/// Message is a shared contact, information about the contact.
@ -401,6 +419,7 @@ pub struct MediaDocument {
pub media_group_id: Option<String>,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MediaGame {
/// Message is a game, information about the game. [More
@ -410,6 +429,7 @@ pub struct MediaGame {
pub game: Game,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MediaLocation {
/// Message is a shared location, information about the location.
@ -439,18 +459,21 @@ pub struct MediaPhoto {
pub media_group_id: Option<String>,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MediaPoll {
/// Message is a native poll, information about the poll.
pub poll: Poll,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MediaSticker {
/// Message is a sticker, information about the sticker.
pub sticker: Sticker,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MediaText {
/// For text messages, the actual UTF-8 text of the message, 0-4096
@ -486,6 +509,7 @@ pub struct MediaVideo {
pub media_group_id: Option<String>,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MediaVideoNote {
/// Message is a [video note], information about the video message.
@ -516,12 +540,14 @@ pub struct MediaVenue {
// Note: for backward compatibility telegram also sends `location` field, but we ignore it
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageDice {
/// Message is a dice with random value from 1 to 6.
pub dice: Dice,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageProximityAlertTriggered {
/// Service message. A user in the chat triggered another user's proximity
@ -529,6 +555,7 @@ pub struct MessageProximityAlertTriggered {
pub proximity_alert_triggered: ProximityAlertTriggered,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageWriteAccessAllowed {
/// Service message: the user allowed the bot added to the attachment menu
@ -536,66 +563,77 @@ pub struct MessageWriteAccessAllowed {
pub write_access_allowed: WriteAccessAllowed,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageForumTopicCreated {
/// Service message: forum topic created.
pub forum_topic_created: ForumTopicCreated,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageForumTopicEdited {
/// Service message: forum topic edited.
pub forum_topic_edited: ForumTopicEdited,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageForumTopicClosed {
/// Service message: forum topic closed.
pub forum_topic_closed: ForumTopicClosed,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageForumTopicReopened {
/// Service message: forum topic reopened.
pub forum_topic_reopened: ForumTopicReopened,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageGeneralForumTopicHidden {
/// Service message: the 'General' forum topic hidden.
pub general_forum_topic_hidden: GeneralForumTopicHidden,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageGeneralForumTopicUnhidden {
/// Service message: the 'General' forum topic unhidden.
pub general_forum_topic_unhidden: GeneralForumTopicUnhidden,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageVideoChatScheduled {
/// Service message: video chat scheduled
pub video_chat_scheduled: VideoChatScheduled,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageVideoChatStarted {
/// Service message: video chat started.
pub video_chat_started: VideoChatStarted,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageVideoChatEnded {
/// Service message: video chat ended.
pub video_chat_ended: VideoChatEnded,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageVideoChatParticipantsInvited {
/// Service message: new participants invited to a video chat.
pub video_chat_participants_invited: VideoChatParticipantsInvited,
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageWebAppData {
/// Service message: data sent by a Web App.