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_action::*;
pub use chat_administrator_rights::*;
pub use chat_background::*;
pub use chat_boost::*;
pub use chat_boost_added::*;
pub use chat_boost_removed::*;
@ -190,6 +191,7 @@ mod callback_query;
mod chat;
mod chat_action;
mod chat_administrator_rights;
mod chat_background;
mod chat_boost;
mod chat_boost_removed;
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 crate::types::{
Animation, Audio, BareChatId, BusinessConnectionId, Chat, ChatBoostAdded, ChatId, ChatShared,
Contact, Dice, Document, ExternalReplyInfo, ForumTopicClosed, ForumTopicCreated,
ForumTopicEdited, ForumTopicReopened, Game, GeneralForumTopicHidden, GeneralForumTopicUnhidden,
Giveaway, GiveawayCompleted, GiveawayCreated, GiveawayWinners, InlineKeyboardMarkup, Invoice,
LinkPreviewOptions, Location, MaybeInaccessibleMessage, MessageAutoDeleteTimerChanged,
MessageEntity, MessageEntityRef, MessageId, MessageOrigin, PassportData, PhotoSize, Poll,
ProximityAlertTriggered, Sticker, Story, SuccessfulPayment, TextQuote, ThreadId, True, User,
UsersShared, Venue, Video, VideoChatEnded, VideoChatParticipantsInvited, VideoChatScheduled,
VideoChatStarted, VideoNote, Voice, WebAppData, WriteAccessAllowed,
Animation, Audio, BareChatId, BusinessConnectionId, Chat, ChatBackground, ChatBoostAdded,
ChatId, ChatShared, Contact, Dice, Document, ExternalReplyInfo, ForumTopicClosed,
ForumTopicCreated, ForumTopicEdited, ForumTopicReopened, Game, GeneralForumTopicHidden,
GeneralForumTopicUnhidden, Giveaway, GiveawayCompleted, GiveawayCreated, GiveawayWinners,
InlineKeyboardMarkup, Invoice, LinkPreviewOptions, Location, MaybeInaccessibleMessage,
MessageAutoDeleteTimerChanged, MessageEntity, MessageEntityRef, MessageId, MessageOrigin,
PassportData, PhotoSize, Poll, ProximityAlertTriggered, Sticker, Story, SuccessfulPayment,
TextQuote, ThreadId, True, User, UsersShared, Venue, Video, VideoChatEnded,
VideoChatParticipantsInvited, VideoChatScheduled, VideoChatStarted, VideoNote, Voice,
WebAppData, WriteAccessAllowed,
};
/// This object represents a message.
@ -90,6 +91,7 @@ pub enum MessageKind {
Dice(MessageDice),
ProximityAlertTriggered(MessageProximityAlertTriggered),
ChatBoostAdded(MessageChatBoostAdded),
ChatBackground(MessageChatBackground),
ForumTopicCreated(MessageForumTopicCreated),
ForumTopicEdited(MessageForumTopicEdited),
ForumTopicClosed(MessageForumTopicClosed),
@ -584,6 +586,13 @@ pub struct MessageChatBoostAdded {
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]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageWriteAccessAllowed {
@ -727,12 +736,12 @@ mod getters {
};
use super::{
MessageChatBoostAdded, MessageForumTopicClosed, MessageForumTopicCreated,
MessageForumTopicEdited, MessageForumTopicReopened, MessageGeneralForumTopicHidden,
MessageGeneralForumTopicUnhidden, MessageGiveaway, MessageGiveawayCompleted,
MessageGiveawayCreated, MessageGiveawayWinners, MessageMessageAutoDeleteTimerChanged,
MessageVideoChatEnded, MessageVideoChatScheduled, MessageVideoChatStarted,
MessageWebAppData, MessageWriteAccessAllowed,
MessageChatBackground, MessageChatBoostAdded, MessageForumTopicClosed,
MessageForumTopicCreated, MessageForumTopicEdited, MessageForumTopicReopened,
MessageGeneralForumTopicHidden, MessageGeneralForumTopicUnhidden, MessageGiveaway,
MessageGiveawayCompleted, MessageGiveawayCreated, MessageGiveawayWinners,
MessageMessageAutoDeleteTimerChanged, MessageVideoChatEnded, MessageVideoChatScheduled,
MessageVideoChatStarted, MessageWebAppData, MessageWriteAccessAllowed,
};
/// 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]
pub fn forum_topic_created(&self) -> Option<&types::ForumTopicCreated> {
match &self.kind {

View file

@ -116,6 +116,7 @@ define_message_ext! {
(filter_dice, Message::dice),
(filter_proximity_alert_triggered, Message::proximity_alert_triggered),
(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_edited, Message::forum_topic_edited),
(filter_forum_topic_closed, Message::forum_topic_closed),