Merge pull request #164 from teloxide/chat_has_protected_content

Add `Chat::has_protected_content`
This commit is contained in:
Waffle Maybe 2022-01-12 11:09:16 +03:00 committed by GitHub
commit e388e79360
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 4 deletions

View file

@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `ApiError::TooMuchInlineQueryResults` ([#135][pr135])
- `ApiError::NotEnoughRightsToChangeChatPermissions` ([#155][pr155])
- Support for 5.4 telegram bot API ([#133][pr133])
- Support for 5.5 telegram bot API ([#143][pr143])
- Support for 5.5 telegram bot API ([#143][pr143], [#164][pr164])
- `EditedMessageIsTooLong` error ([#109][pr109])
- `UntilDate` enum and use it for `{Restricted, Banned}::until_date` ([#116][pr116])
- `Limits::messages_per_min_channel` ([#121][pr121])
@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[pr143]: https://github.com/teloxide/teloxide-core/pull/143
[pr151]: https://github.com/teloxide/teloxide-core/pull/151
[pr155]: https://github.com/teloxide/teloxide-core/pull/155
[pr164]: https://github.com/teloxide/teloxide-core/pull/164
### Changed

View file

@ -70,6 +70,12 @@ pub struct ChatPublic {
///
/// [`GetChat`]: crate::payloads::GetChat
pub invite_link: Option<String>,
/// `True`, if messages from the chat can't be forwarded to other chats.
/// Returned only in [`GetChat`].
///
/// [`GetChat`]: crate::payloads::GetChat
pub has_protected_content: Option<True>,
}
#[serde_with_macros::skip_serializing_none]
@ -97,7 +103,7 @@ pub struct ChatPrivate {
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
/// allows to use `tg://user?id=<user_id>` links only in chats with the
/// user. Returned only in [`GetChat`].
///
/// [`GetChat`]: crate::payloads::GetChat
@ -389,6 +395,17 @@ impl Chat {
}
}
/// `True`, if messages from the chat can't be forwarded to other chats.
/// Returned only in [`GetChat`].
///
/// [`GetChat`]: crate::payloads::GetChat
pub fn has_protected_content(&self) -> Option<True> {
match &self.kind {
ChatKind::Public(this) => this.has_protected_content,
_ => None,
}
}
/// A first name of the other party in a private chat.
pub fn first_name(&self) -> Option<&str> {
match &self.kind {
@ -446,6 +463,7 @@ mod tests {
}),
description: None,
invite_link: None,
has_protected_content: None,
}),
photo: None,
pinned_message: None,
@ -466,7 +484,7 @@ mod tests {
first_name: Some("Anon".into()),
last_name: None,
bio: None,
has_private_forwards: None
has_private_forwards: None,
}),
photo: None,
pinned_message: None,

View file

@ -1339,10 +1339,11 @@ mod tests {
}),
description: None,
invite_link: None,
has_protected_content: None,
}),
message_auto_delete_time: None,
photo: None,
pinned_message: None,
message_auto_delete_time: None,
};
assert!(message.from().unwrap().is_anonymous());