Add ChatBackground variant to MessageKind enum

and add `filter_chat_background_set` to `MessageFilterExt` trait
This commit is contained in:
Andrey Brusnik 2024-08-19 19:29:07 +04:00
parent 63e0448b28
commit 09d7b06079
No known key found for this signature in database
GPG key ID: D33232F28CFF442C
4 changed files with 50 additions and 15 deletions

View file

@ -23,6 +23,7 @@ pub use callback_query::*;
pub use chat::*; pub use chat::*;
pub use chat_action::*; pub use chat_action::*;
pub use chat_administrator_rights::*; pub use chat_administrator_rights::*;
pub use chat_background::*;
pub use chat_boost::*; pub use chat_boost::*;
pub use chat_boost_added::*; pub use chat_boost_added::*;
pub use chat_boost_removed::*; pub use chat_boost_removed::*;
@ -190,6 +191,7 @@ mod callback_query;
mod chat; mod chat;
mod chat_action; mod chat_action;
mod chat_administrator_rights; mod chat_administrator_rights;
mod chat_background;
mod chat_boost; mod chat_boost;
mod chat_boost_removed; mod chat_boost_removed;
mod chat_boost_source; mod chat_boost_source;

View file

@ -0,0 +1,13 @@
use serde::{Deserialize, Serialize};
use crate::types::BackgroundType;
/// This object represents a chat background.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug)]
#[derive(PartialEq, Eq, Hash)]
#[derive(Serialize, Deserialize)]
pub struct ChatBackground {
/// Type of the background
pub r#type: BackgroundType,
}

View file

@ -5,15 +5,16 @@ use serde::{Deserialize, Serialize};
use url::Url; use url::Url;
use crate::types::{ use crate::types::{
Animation, Audio, BareChatId, BusinessConnectionId, Chat, ChatBoostAdded, ChatId, ChatShared, Animation, Audio, BareChatId, BusinessConnectionId, Chat, ChatBackground, ChatBoostAdded,
Contact, Dice, Document, ExternalReplyInfo, ForumTopicClosed, ForumTopicCreated, ChatId, ChatShared, Contact, Dice, Document, ExternalReplyInfo, ForumTopicClosed,
ForumTopicEdited, ForumTopicReopened, Game, GeneralForumTopicHidden, GeneralForumTopicUnhidden, ForumTopicCreated, ForumTopicEdited, ForumTopicReopened, Game, GeneralForumTopicHidden,
Giveaway, GiveawayCompleted, GiveawayCreated, GiveawayWinners, InlineKeyboardMarkup, Invoice, GeneralForumTopicUnhidden, Giveaway, GiveawayCompleted, GiveawayCreated, GiveawayWinners,
LinkPreviewOptions, Location, MaybeInaccessibleMessage, MessageAutoDeleteTimerChanged, InlineKeyboardMarkup, Invoice, LinkPreviewOptions, Location, MaybeInaccessibleMessage,
MessageEntity, MessageEntityRef, MessageId, MessageOrigin, PassportData, PhotoSize, Poll, MessageAutoDeleteTimerChanged, MessageEntity, MessageEntityRef, MessageId, MessageOrigin,
ProximityAlertTriggered, Sticker, Story, SuccessfulPayment, TextQuote, ThreadId, True, User, PassportData, PhotoSize, Poll, ProximityAlertTriggered, Sticker, Story, SuccessfulPayment,
UsersShared, Venue, Video, VideoChatEnded, VideoChatParticipantsInvited, VideoChatScheduled, TextQuote, ThreadId, True, User, UsersShared, Venue, Video, VideoChatEnded,
VideoChatStarted, VideoNote, Voice, WebAppData, WriteAccessAllowed, VideoChatParticipantsInvited, VideoChatScheduled, VideoChatStarted, VideoNote, Voice,
WebAppData, WriteAccessAllowed,
}; };
/// This object represents a message. /// This object represents a message.
@ -90,6 +91,7 @@ pub enum MessageKind {
Dice(MessageDice), Dice(MessageDice),
ProximityAlertTriggered(MessageProximityAlertTriggered), ProximityAlertTriggered(MessageProximityAlertTriggered),
ChatBoostAdded(MessageChatBoostAdded), ChatBoostAdded(MessageChatBoostAdded),
ChatBackground(MessageChatBackground),
ForumTopicCreated(MessageForumTopicCreated), ForumTopicCreated(MessageForumTopicCreated),
ForumTopicEdited(MessageForumTopicEdited), ForumTopicEdited(MessageForumTopicEdited),
ForumTopicClosed(MessageForumTopicClosed), ForumTopicClosed(MessageForumTopicClosed),
@ -584,6 +586,13 @@ pub struct MessageChatBoostAdded {
pub boost_added: ChatBoostAdded, pub boost_added: ChatBoostAdded,
} }
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageChatBackground {
/// Service message. Chat background set.
pub chat_background_set: ChatBackground,
}
#[serde_with::skip_serializing_none] #[serde_with::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageWriteAccessAllowed { pub struct MessageWriteAccessAllowed {
@ -727,12 +736,12 @@ mod getters {
}; };
use super::{ use super::{
MessageChatBoostAdded, MessageForumTopicClosed, MessageForumTopicCreated, MessageChatBackground, MessageChatBoostAdded, MessageForumTopicClosed,
MessageForumTopicEdited, MessageForumTopicReopened, MessageGeneralForumTopicHidden, MessageForumTopicCreated, MessageForumTopicEdited, MessageForumTopicReopened,
MessageGeneralForumTopicUnhidden, MessageGiveaway, MessageGiveawayCompleted, MessageGeneralForumTopicHidden, MessageGeneralForumTopicUnhidden, MessageGiveaway,
MessageGiveawayCreated, MessageGiveawayWinners, MessageMessageAutoDeleteTimerChanged, MessageGiveawayCompleted, MessageGiveawayCreated, MessageGiveawayWinners,
MessageVideoChatEnded, MessageVideoChatScheduled, MessageVideoChatStarted, MessageMessageAutoDeleteTimerChanged, MessageVideoChatEnded, MessageVideoChatScheduled,
MessageWebAppData, MessageWriteAccessAllowed, MessageVideoChatStarted, MessageWebAppData, MessageWriteAccessAllowed,
}; };
/// Getters for [Message] fields from [telegram docs]. /// Getters for [Message] fields from [telegram docs].
@ -1414,6 +1423,16 @@ mod getters {
} }
} }
#[must_use]
pub fn chat_background_set(&self) -> Option<&types::ChatBackground> {
match &self.kind {
ChatBackground(MessageChatBackground { chat_background_set }) => {
Some(chat_background_set)
}
_ => None,
}
}
#[must_use] #[must_use]
pub fn forum_topic_created(&self) -> Option<&types::ForumTopicCreated> { pub fn forum_topic_created(&self) -> Option<&types::ForumTopicCreated> {
match &self.kind { match &self.kind {

View file

@ -116,6 +116,7 @@ define_message_ext! {
(filter_dice, Message::dice), (filter_dice, Message::dice),
(filter_proximity_alert_triggered, Message::proximity_alert_triggered), (filter_proximity_alert_triggered, Message::proximity_alert_triggered),
(filter_boost_added, Message::boost_added), (filter_boost_added, Message::boost_added),
(filter_chat_background_set, Message::chat_background_set),
(filter_forum_topic_created, Message::forum_topic_created), (filter_forum_topic_created, Message::forum_topic_created),
(filter_forum_topic_edited, Message::forum_topic_edited), (filter_forum_topic_edited, Message::forum_topic_edited),
(filter_forum_topic_closed, Message::forum_topic_closed), (filter_forum_topic_closed, Message::forum_topic_closed),