From 02f023cfb6bf3b4f2923a9036b3d3ba646d8c6f8 Mon Sep 17 00:00:00 2001 From: Andrey Brusnik Date: Mon, 15 Jul 2024 16:41:11 +0400 Subject: [PATCH 1/5] 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, From cef06d21de4236d619d9e2a933552c234c075445 Mon Sep 17 00:00:00 2001 From: Andrey Brusnik Date: Mon, 15 Jul 2024 18:25:47 +0400 Subject: [PATCH 2/5] Add `can_post_stories`, `can_edit_stories` and `can_delete_stories` parameters to PromoteChatMember --- crates/teloxide-core/schema.ron | 15 +++++++++++++++ .../src/payloads/promote_chat_member.rs | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/crates/teloxide-core/schema.ron b/crates/teloxide-core/schema.ron index cc649e5d..7cd1647b 100644 --- a/crates/teloxide-core/schema.ron +++ b/crates/teloxide-core/schema.ron @@ -2041,6 +2041,21 @@ Schema( ty: Option(bool), descr: Doc(md: "Pass True, if the administrator can delete messages of other users") ), + Param( + name: "can_post_stories", + ty: Option(bool), + descr: Doc(md: "Pass True, if the administrator can post stories in the channel, channels only") + ), + Param( + name: "can_edit_stories", + ty: Option(bool), + descr: Doc(md: "Pass True, if the administrator can edit stories posted by other users, channels only") + ), + Param( + name: "can_delete_stories", + ty: Option(bool), + descr: Doc(md: "Pass True, if the administrator can delete stories posted by other users, channels only") + ), Param( name: "can_manage_video_chats", ty: Option(bool), diff --git a/crates/teloxide-core/src/payloads/promote_chat_member.rs b/crates/teloxide-core/src/payloads/promote_chat_member.rs index 9b8bac40..851abdd4 100644 --- a/crates/teloxide-core/src/payloads/promote_chat_member.rs +++ b/crates/teloxide-core/src/payloads/promote_chat_member.rs @@ -25,6 +25,12 @@ impl_payload! { pub can_edit_messages: bool, /// Pass True, if the administrator can delete messages of other users pub can_delete_messages: bool, + /// Pass True, if the administrator can post stories in the channel, channels only + pub can_post_stories: bool, + /// Pass True, if the administrator can edit stories posted by other users, channels only + pub can_edit_stories: bool, + /// Pass True, if the administrator can delete stories posted by other users, channels only + pub can_delete_stories: bool, /// Pass True, if the administrator can manage video chats, supergroups only pub can_manage_video_chats: bool, /// Pass True, if the administrator can restrict, ban or unban chat members From c971d83330c6e66a6ea6e3ce38371e8034446833 Mon Sep 17 00:00:00 2001 From: Andrey Brusnik Date: Mon, 15 Jul 2024 19:58:18 +0400 Subject: [PATCH 3/5] Add `from_request` and `from_attachment_menu` fields to `WriteAccessAllowed` --- crates/teloxide-core/src/types/write_access_allowed.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/teloxide-core/src/types/write_access_allowed.rs b/crates/teloxide-core/src/types/write_access_allowed.rs index 7c6b3629..36f29b4a 100644 --- a/crates/teloxide-core/src/types/write_access_allowed.rs +++ b/crates/teloxide-core/src/types/write_access_allowed.rs @@ -10,4 +10,10 @@ use serde::{Deserialize, Serialize}; pub struct WriteAccessAllowed { /// Name of the Web App which was launched from a link pub web_app_name: Option, + /// `true`, if the access was granted after the user accepted an explicit + /// request from a Web App sent by the method [requestWriteAccess](https://core.telegram.org/bots/webapps#initializing-mini-apps) + pub from_request: Option, + /// `true`, if the access was granted when the bot was added to the + /// attachment or side menu + pub from_attachment_menu: Option, } From 8c26a30b9bbed199f9b658a2c382e1777c414862 Mon Sep 17 00:00:00 2001 From: Andrey Brusnik Date: Mon, 15 Jul 2024 20:30:23 +0400 Subject: [PATCH 4/5] Update CHANGELOG.md & README.md --- README.md | 2 +- crates/teloxide-core/CHANGELOG.md | 4 ++++ crates/teloxide-core/README.md | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6eda6f18..66e81040 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ - + diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index 951ca6b0..ac40fb82 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -85,6 +85,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `PollAnswer::voter` to support anonymous poll answers in chats - `emoji_status_expiration_date` to `Chat` as part of the future `ChatFullInfo` type TBA type - Add the `unpin_all_general_forum_topic_messages` method +- Support for TBA 6.9 ([#1095](pr1095)) + - Add `can_post_stories`, `can_edit_stories` and `can_delete_stories` fields to `ChatMemberKind::Administrator`, `ChatAdministratorRights` and `PromoteChatMember` + - Add `from_request` and `from_attachment_menu` fields to `WriteAccessAllowed` [pr851]: https://github.com/teloxide/teloxide/pull/851 [pr887]: https://github.com/teloxide/teloxide/pull/887 @@ -93,6 +96,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [pr1040]: https://github.com/teloxide/teloxide/pull/1040 [pr1086]: https://github.com/teloxide/teloxide/pull/1086 [pr1087]: https://github.com/teloxide/teloxide/pull/1087 +[pr1095]: https://github.com/teloxide/teloxide/pull/1095 ### Fixed diff --git a/crates/teloxide-core/README.md b/crates/teloxide-core/README.md index 6a382bb3..d4748be4 100644 --- a/crates/teloxide-core/README.md +++ b/crates/teloxide-core/README.md @@ -12,7 +12,7 @@ - + From 116c635804a909278b4b9de696cc4f145b7f4aaf Mon Sep 17 00:00:00 2001 From: Andrey Brusnik Date: Wed, 17 Jul 2024 21:58:27 +0400 Subject: [PATCH 5/5] Bump TBA version in schema --- crates/teloxide-core/schema.ron | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/teloxide-core/schema.ron b/crates/teloxide-core/schema.ron index 7cd1647b..0f311684 100644 --- a/crates/teloxide-core/schema.ron +++ b/crates/teloxide-core/schema.ron @@ -39,7 +39,7 @@ //! [github]: https://github.com/WaffleLapkin/tg-methods-schema Schema( - api_version: ApiVersion(ver: "6.8", date: "August 18, 2023"), + api_version: ApiVersion(ver: "6.9", date: "September 22, 2023"), methods: [ Method( names: ("getUpdates", "GetUpdates", "get_updates"),