From 02f023cfb6bf3b4f2923a9036b3d3ba646d8c6f8 Mon Sep 17 00:00:00 2001 From: Andrey Brusnik Date: Mon, 15 Jul 2024 16:41:11 +0400 Subject: [PATCH] Add `can_post_stories`, `can_edit_stories` and `can_delete_stories` privileges to ChatMemberKind::Administrator and ChatAdministratorRights --- .../src/types/chat_administrator_rights.rs | 12 +++ crates/teloxide-core/src/types/chat_member.rs | 78 +++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/crates/teloxide-core/src/types/chat_administrator_rights.rs b/crates/teloxide-core/src/types/chat_administrator_rights.rs index 6c5168a6..c3e9c62c 100644 --- a/crates/teloxide-core/src/types/chat_administrator_rights.rs +++ b/crates/teloxide-core/src/types/chat_administrator_rights.rs @@ -47,6 +47,18 @@ pub struct ChatAdministratorRights { /// supergroups only pub can_pin_messages: Option, + /// `true`, if the administrator can post stories in the channel; + /// channels only + pub can_post_stories: Option, + + /// `true`, if the administrator can edit stories posted by other users; + /// channels only + pub can_edit_stories: Option, + + /// `true`, if the administrator can delete stories posted by other users; + /// channels only + pub can_delete_stories: Option, + /// `true`, if the user is allowed to create, rename, close, and reopen /// forum topics; supergroups only pub can_manage_topics: Option, diff --git a/crates/teloxide-core/src/types/chat_member.rs b/crates/teloxide-core/src/types/chat_member.rs index 1e195548..5aec15ee 100644 --- a/crates/teloxide-core/src/types/chat_member.rs +++ b/crates/teloxide-core/src/types/chat_member.rs @@ -80,6 +80,21 @@ pub struct Administrator { /// `true` if the administrator can delete messages of other users. pub can_delete_messages: bool, + /// `true` if the administrator can post stories in the channel, channels + /// only. + #[serde(default)] + pub can_post_stories: bool, + + /// `true` if the administrator can edit stories posted by other users, + /// channels only. + #[serde(default)] + pub can_edit_stories: bool, + + /// `true` if the administrator can delete stories posted by other users, + /// channels only. + #[serde(default)] + pub can_delete_stories: bool, + /// `true` if the administrator can manage video chats. pub can_manage_video_chats: bool, @@ -432,6 +447,66 @@ impl ChatMemberKind { } } + /// Returns `true` if the user can post stories in the channel, channels + /// only. + /// + /// I.e. returns `true` if the user + /// - is the owner of the chat (even if the chat is not a channel) + /// - is an administrator in the given chat and has [`can_post_stories`] + /// privilege. + /// + /// Returns `false` otherwise. + /// + /// [`can_post_stories`]: Administrator::can_post_stories + #[must_use] + pub fn can_post_stories(&self) -> bool { + match self { + Self::Owner(_) => true, + Self::Administrator(Administrator { can_post_stories, .. }) => *can_post_stories, + Self::Member | Self::Restricted(_) | Self::Left | Self::Banned(_) => false, + } + } + + /// Returns `true` if the user can edit stories posted by other users, + /// channels only. + /// + /// I.e. returns `true` if the user + /// - is the owner of the chat (even if the chat is not a channel) + /// - is an administrator in the given chat and has the [`can_edit_stories`] + /// privilege. + /// + /// Returns `false` otherwise. + /// + /// [`can_edit_stories`]: Administrator::can_edit_stories + #[must_use] + pub fn can_edit_stories(&self) -> bool { + match self { + Self::Owner(_) => true, + Self::Administrator(Administrator { can_edit_stories, .. }) => *can_edit_stories, + Self::Member | Self::Restricted(_) | Self::Left | Self::Banned(_) => false, + } + } + + /// Returns `true` if the user can delete stories posted by other users, + /// channels only. + /// + /// I.e. returns `true` if the user + /// - is the owner of the chat + /// - is an administrator in the given chat and has the + /// [`can_delete_stories`] privilege. + /// + /// Returns `false` otherwise. + /// + /// [`can_delete_stories`]: Administrator::can_delete_stories + #[must_use] + pub fn can_delete_stories(&self) -> bool { + match self { + Self::Owner(_) => true, + Self::Administrator(Administrator { can_delete_stories, .. }) => *can_delete_stories, + Self::Member | Self::Restricted(_) | Self::Left | Self::Banned(_) => false, + } + } + /// Returns `true` if the user can manage video chats. /// /// I.e. returns `true` if the user @@ -639,6 +714,9 @@ mod tests { can_post_messages: false, can_edit_messages: false, can_delete_messages: true, + can_post_stories: false, + can_edit_stories: false, + can_delete_stories: false, can_manage_video_chats: true, can_invite_users: true, can_restrict_members: true,