Add EditedBusinessMessage variant to UpdateKind

This commit is contained in:
Akshett Rai Jindal 2024-08-21 01:52:44 +05:30
parent 9e57d3acff
commit 0efb15aa6a
4 changed files with 40 additions and 19 deletions

View file

@ -9,6 +9,7 @@ pub enum AllowedUpdate {
EditedChannelPost,
BusinessConnection,
BusinessMessage,
EditedBusinessMessage,
MessageReaction,
MessageReactionCount,
InlineQuery,

View file

@ -67,6 +67,9 @@ pub enum UpdateKind {
/// New non-service message from a connected business account
BusinessMessage(Message),
/// New version of a message from a connected business account
EditedBusinessMessage(Message),
/// A reaction to a message was changed by a user. The bot must be an
/// administrator in the chat and must explicitly specify
/// [`AllowedUpdate::MessageReaction`] in the list of `allowed_updates`
@ -163,8 +166,12 @@ impl Update {
use UpdateKind::*;
let from = match &self.kind {
Message(m) | EditedMessage(m) | ChannelPost(m) | EditedChannelPost(m)
| BusinessMessage(m) => m.from.as_ref()?,
Message(m)
| EditedMessage(m)
| ChannelPost(m)
| EditedChannelPost(m)
| BusinessMessage(m)
| EditedBusinessMessage(m) => m.from.as_ref()?,
BusinessConnection(conn) => &conn.user,
@ -230,7 +237,8 @@ impl Update {
| UpdateKind::EditedMessage(message)
| UpdateKind::ChannelPost(message)
| UpdateKind::EditedChannelPost(message)
| UpdateKind::BusinessMessage(message) => i0(message.mentioned_users()),
| UpdateKind::BusinessMessage(message)
| UpdateKind::EditedBusinessMessage(message) => i0(message.mentioned_users()),
UpdateKind::MessageReaction(answer) => {
if let Some(user) = answer.user() {
@ -283,8 +291,12 @@ impl Update {
use UpdateKind::*;
let chat = match &self.kind {
Message(m) | EditedMessage(m) | ChannelPost(m) | EditedChannelPost(m)
| BusinessMessage(m) => &m.chat,
Message(m)
| EditedMessage(m)
| ChannelPost(m)
| EditedChannelPost(m)
| BusinessMessage(m)
| EditedBusinessMessage(m) => &m.chat,
CallbackQuery(q) => q.message.as_ref()?.chat(),
ChatMember(m) => &m.chat,
MyChatMember(m) => &m.chat,
@ -370,6 +382,9 @@ impl<'de> Deserialize<'de> for UpdateKind {
"business_message" => {
map.next_value::<Message>().ok().map(UpdateKind::BusinessMessage)
}
"edited_business_message" => {
map.next_value::<Message>().ok().map(UpdateKind::EditedBusinessMessage)
}
"message_reaction" => map
.next_value::<MessageReactionUpdated>()
.ok()
@ -449,37 +464,40 @@ impl Serialize for UpdateKind {
UpdateKind::BusinessMessage(v) => {
s.serialize_newtype_variant(name, 5, "business_message", v)
}
UpdateKind::EditedBusinessMessage(v) => {
s.serialize_newtype_variant(name, 6, "edited_business_message", v)
}
UpdateKind::MessageReaction(v) => {
s.serialize_newtype_variant(name, 6, "message_reaction", v)
s.serialize_newtype_variant(name, 7, "message_reaction", v)
}
UpdateKind::MessageReactionCount(v) => {
s.serialize_newtype_variant(name, 7, "message_reaction_count", v)
s.serialize_newtype_variant(name, 8, "message_reaction_count", v)
}
UpdateKind::InlineQuery(v) => s.serialize_newtype_variant(name, 8, "inline_query", v),
UpdateKind::InlineQuery(v) => s.serialize_newtype_variant(name, 9, "inline_query", v),
UpdateKind::ChosenInlineResult(v) => {
s.serialize_newtype_variant(name, 9, "chosen_inline_result", v)
s.serialize_newtype_variant(name, 10, "chosen_inline_result", v)
}
UpdateKind::CallbackQuery(v) => {
s.serialize_newtype_variant(name, 10, "callback_query", v)
s.serialize_newtype_variant(name, 11, "callback_query", v)
}
UpdateKind::ShippingQuery(v) => {
s.serialize_newtype_variant(name, 11, "shipping_query", v)
s.serialize_newtype_variant(name, 12, "shipping_query", v)
}
UpdateKind::PreCheckoutQuery(v) => {
s.serialize_newtype_variant(name, 12, "pre_checkout_query", v)
s.serialize_newtype_variant(name, 13, "pre_checkout_query", v)
}
UpdateKind::Poll(v) => s.serialize_newtype_variant(name, 13, "poll", v),
UpdateKind::PollAnswer(v) => s.serialize_newtype_variant(name, 14, "poll_answer", v),
UpdateKind::Poll(v) => s.serialize_newtype_variant(name, 14, "poll", v),
UpdateKind::PollAnswer(v) => s.serialize_newtype_variant(name, 15, "poll_answer", v),
UpdateKind::MyChatMember(v) => {
s.serialize_newtype_variant(name, 15, "my_chat_member", v)
s.serialize_newtype_variant(name, 16, "my_chat_member", v)
}
UpdateKind::ChatMember(v) => s.serialize_newtype_variant(name, 16, "chat_member", v),
UpdateKind::ChatMember(v) => s.serialize_newtype_variant(name, 17, "chat_member", v),
UpdateKind::ChatJoinRequest(v) => {
s.serialize_newtype_variant(name, 17, "chat_join_request", v)
s.serialize_newtype_variant(name, 18, "chat_join_request", v)
}
UpdateKind::ChatBoost(v) => s.serialize_newtype_variant(name, 18, "chat_boost", v),
UpdateKind::ChatBoost(v) => s.serialize_newtype_variant(name, 19, "chat_boost", v),
UpdateKind::RemovedChatBoost(v) => {
s.serialize_newtype_variant(name, 19, "removed_chat_boost", v)
s.serialize_newtype_variant(name, 20, "removed_chat_boost", v)
}
UpdateKind::Error(v) => v.serialize(s),
}

View file

@ -157,6 +157,7 @@ define_update_ext! {
(filter_edited_channel_post, UpdateKind::EditedChannelPost, EditedChannelPost),
(filter_business_connection, UpdateKind::BusinessConnection, BusinessConnection),
(filter_business_message, UpdateKind::BusinessMessage, BusinessMessage),
(filter_edited_business_message, UpdateKind::EditedBusinessMessage, EditedBusinessMessage),
(filter_message_reaction_updated, UpdateKind::MessageReaction, MessageReaction),
(filter_message_reaction_count_updated, UpdateKind::MessageReactionCount, MessageReactionCount),
(filter_inline_query, UpdateKind::InlineQuery, InlineQuery),

View file

@ -67,6 +67,7 @@ impl EventKind for Kind {
EditedChannelPost,
BusinessConnection,
BusinessMessage,
EditedBusinessMessage,
MessageReaction,
MessageReactionCount,
InlineQuery,