TBA 5.5 types updates

This commit is contained in:
Maybe Waffle 2021-12-08 21:30:03 +03:00
parent c566494b7d
commit 604a5cc91b
4 changed files with 60 additions and 2 deletions

View file

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use crate::types::{ChatLocation, ChatPermissions, ChatPhoto, Message};
use crate::types::{ChatLocation, ChatPermissions, ChatPhoto, Message, True};
/// This object represents a chat.
///
@ -95,6 +95,13 @@ pub struct ChatPrivate {
///
/// [`GetChat`]: crate::payloads::GetChat
pub bio: Option<String>,
/// `True`, if privacy settings of the other party in the private chat
/// allows to use tg://user?id=<user_id> links only in chats with the
/// user. Returned only in [`GetChat`].
///
/// [`GetChat`]: crate::payloads::GetChat
pub has_private_forwards: Option<True>,
}
#[serde_with_macros::skip_serializing_none]
@ -407,6 +414,18 @@ impl Chat {
_ => None,
}
}
/// `True`, if privacy settings of the other party in the private chat
/// allows to use tg://user?id=<user_id> links only in chats with the
/// user. Returned only in [`GetChat`].
///
/// [`GetChat`]: crate::payloads::GetChat
pub fn has_private_forwards(&self) -> Option<True> {
match &self.kind {
ChatKind::Private(this) => this.has_private_forwards,
_ => None,
}
}
}
#[cfg(test)]
@ -447,6 +466,7 @@ mod tests {
first_name: Some("Anon".into()),
last_name: None,
bio: None,
has_private_forwards: None
}),
photo: None,
pinned_message: None,

View file

@ -41,7 +41,13 @@ impl InlineKeyboardButton {
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum InlineKeyboardButtonKind {
/// HTTP or tg:// url to be opened when button is pressed.
/// HTTP or `tg://` url to be opened when button is pressed.
///
/// Links in the form of `tg://user?id=<user_id>` can be used to mention a
/// user by their ID without using a username, if this is allowed by
/// their privacy settings. This will only work in Telegram versions
/// released after December 7, 2021. Older clients will display _unsupported
/// message_.
Url(reqwest::Url),
/// An HTTP URL used to automatically authorize the user. Can be used as a

View file

@ -90,6 +90,15 @@ pub struct MessageCommon {
/// Inline keyboard attached to the message. `login_url` buttons are
/// represented as ordinary `url` buttons.
pub reply_markup: Option<InlineKeyboardMarkup>,
/// `true`, if the message is a channel post that was automatically
/// forwarded to the connected discussion group.
#[serde(default)]
pub is_automatic_forward: bool,
/// `true`, if the message can't be forwarded.
#[serde(default)]
pub has_protected_content: bool,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
@ -1006,6 +1015,26 @@ mod getters {
_ => None,
}
}
pub fn is_automatic_forward(&self) -> bool {
match &self.kind {
Common(MessageCommon {
is_automatic_forward,
..
}) => *is_automatic_forward,
_ => false,
}
}
pub fn has_protected_content(&self) -> bool {
match &self.kind {
Common(MessageCommon {
has_protected_content,
..
}) => *has_protected_content,
_ => false,
}
}
}
}

View file

@ -193,6 +193,7 @@ mod test {
first_name: Some(String::from("Waffle")),
last_name: None,
bio: None,
has_private_forwards: None,
}),
photo: None,
pinned_message: None,
@ -218,6 +219,8 @@ mod test {
reply_markup: None,
sender_chat: None,
author_signature: None,
is_automatic_forward: false,
has_protected_content: false,
}),
}),
};