From 7288e90211354fe720df6b083be6a3d4be37911a Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 17 Jan 2023 18:13:27 +0300 Subject: [PATCH] Untie can_send_messages right from other rights. --- td/generate/scheme/td_api.tl | 18 +++++++++--------- td/telegram/DialogParticipant.cpp | 28 +++++++++------------------- td/telegram/MessagesManager.cpp | 3 --- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index ae389e840..4eec428ea 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -563,15 +563,15 @@ inputChatPhotoAnimation animation:InputFile main_frame_timestamp:double = InputC //@description Describes actions that a user is allowed to take in a chat //@can_send_messages True, if the user can send text messages, contacts, invoices, locations, and venues -//@can_send_audios True, if the user can send music files. Implies can_send_messages permissions -//@can_send_documents True, if the user can send documents. Implies can_send_messages permissions -//@can_send_photos True, if the user can send audio photos. Implies can_send_messages permissions -//@can_send_videos True, if the user can send audio videos. Implies can_send_messages permissions -//@can_send_video_notes True, if the user can send video notes. Implies can_send_messages permissions -//@can_send_voice_notes True, if the user can send voice notes. Implies can_send_messages permissions -//@can_send_polls True, if the user can send polls. Implies can_send_messages permissions -//@can_send_other_messages True, if the user can send animations, games, stickers, and dice and use inline bots. Implies can_send_messages permissions -//@can_add_web_page_previews True, if the user may add a web page preview to their messages. Implies can_send_messages permissions +//@can_send_audios True, if the user can send music files +//@can_send_documents True, if the user can send documents +//@can_send_photos True, if the user can send audio photos +//@can_send_videos True, if the user can send audio videos +//@can_send_video_notes True, if the user can send video notes +//@can_send_voice_notes True, if the user can send voice notes +//@can_send_polls True, if the user can send polls +//@can_send_other_messages True, if the user can send animations, games, stickers, and dice and use inline bots +//@can_add_web_page_previews True, if the user may add a web page preview to their messages //@can_change_info True, if the user can change the chat title, photo, and other settings //@can_invite_users True, if the user can invite new users to the chat //@can_pin_messages True, if the user can pin messages diff --git a/td/telegram/DialogParticipant.cpp b/td/telegram/DialogParticipant.cpp index 7366c5311..de58c3aad 100644 --- a/td/telegram/DialogParticipant.cpp +++ b/td/telegram/DialogParticipant.cpp @@ -210,22 +210,12 @@ RestrictedRights::RestrictedRights(const td_api::object_ptrcan_send_polls_; - bool can_send_audios = rights->can_send_audios_; - bool can_send_documents = rights->can_send_documents_; - bool can_send_photos = rights->can_send_photos_; - bool can_send_videos = rights->can_send_videos_; - bool can_send_video_notes = rights->can_send_video_notes_; - bool can_send_voice_notes = rights->can_send_voice_notes_; - bool can_send_messages = rights->can_send_messages_ || can_send_audios || can_send_documents || can_send_photos || - can_send_videos || can_send_video_notes || can_send_voice_notes || can_send_polls || - rights->can_send_other_messages_ || rights->can_add_web_page_previews_; - *this = RestrictedRights(can_send_messages, can_send_audios, can_send_documents, can_send_photos, can_send_videos, - can_send_video_notes, can_send_voice_notes, rights->can_send_other_messages_, - rights->can_send_other_messages_, rights->can_send_other_messages_, - rights->can_send_other_messages_, rights->can_add_web_page_previews_, can_send_polls, - rights->can_change_info_, rights->can_invite_users_, rights->can_pin_messages_, - rights->can_manage_topics_); + *this = RestrictedRights( + rights->can_send_messages_, rights->can_send_audios_, rights->can_send_documents_, rights->can_send_photos_, + rights->can_send_videos_, rights->can_send_video_notes_, rights->can_send_voice_notes_, + rights->can_send_other_messages_, rights->can_send_other_messages_, rights->can_send_other_messages_, + rights->can_send_other_messages_, rights->can_add_web_page_previews_, rights->can_send_polls_, + rights->can_change_info_, rights->can_invite_users_, rights->can_pin_messages_, rights->can_manage_topics_); } RestrictedRights::RestrictedRights(bool can_send_messages, bool can_send_audios, bool can_send_documents, @@ -265,7 +255,7 @@ td_api::object_ptr RestrictedRights::get_chat_permissio tl_object_ptr RestrictedRights::get_chat_banned_rights() const { int32 flags = 0; if (!can_send_messages()) { - flags |= telegram_api::chatBannedRights::SEND_MESSAGES_MASK; + flags |= telegram_api::chatBannedRights::SEND_PLAIN_MASK; } if (!can_send_audios()) { flags |= telegram_api::chatBannedRights::SEND_AUDIOS_MASK; @@ -335,7 +325,7 @@ bool operator!=(const RestrictedRights &lhs, const RestrictedRights &rhs) { StringBuilder &operator<<(StringBuilder &string_builder, const RestrictedRights &status) { string_builder << "Restricted: "; if (!status.can_send_messages()) { - string_builder << "(text)"; + string_builder << "(text+contact+invoice+location+venue)"; } if (!status.can_send_audios()) { string_builder << "(audios)"; @@ -356,7 +346,7 @@ StringBuilder &operator<<(StringBuilder &string_builder, const RestrictedRights string_builder << "(voice notes)"; } if (!status.can_send_stickers()) { - string_builder << "(stickers)"; + string_builder << "(stickers+dices)"; } if (!status.can_send_animations()) { string_builder << "(animations)"; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 4bc8125fd..e1addd1df 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -25879,9 +25879,6 @@ Status MessagesManager::can_send_message(DialogId dialog_id) const { switch (channel_type) { case ChannelType::Unknown: case ChannelType::Megagroup: - if (!channel_status.can_send_messages()) { - return Status::Error(400, "Have no rights to send a message"); - } break; case ChannelType::Broadcast: { if (!channel_status.can_post_messages()) {