From 825cb0dd0b684f40962c07a605ba6e70fc6258e2 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 11 Oct 2019 03:28:41 +0300 Subject: [PATCH] Add removeChatActionBar. GitOrigin-RevId: 865c60b541cdfdc1465ab4814e1ca8c2c9ff0c49 --- td/generate/scheme/td_api.tl | 3 +++ td/generate/scheme/td_api.tlo | Bin 161260 -> 161352 bytes td/telegram/MessagesManager.cpp | 37 +++++++++++++++++++++++++++++--- td/telegram/MessagesManager.h | 2 ++ td/telegram/Td.cpp | 6 ++++++ td/telegram/Td.h | 2 ++ td/telegram/cli.cpp | 3 +++ 7 files changed, 50 insertions(+), 3 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index b952a7b94..707f680f0 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3907,6 +3907,9 @@ getChatReportSpamState chat_id:int53 = ChatReportSpamState; //@description Reports to the server whether a chat is a spam chat or not. Can be used only if ChatReportSpamState.can_report_spam is true. After this request, ChatReportSpamState.can_report_spam becomes false forever @chat_id Chat identifier @is_spam_chat If true, the chat will be reported as spam; otherwise it will be marked as not spam changeChatReportSpamState chat_id:int53 is_spam_chat:Bool = Ok; +//@description Removes a chat action bar without any other action @chat_id Chat identifier +removeChatActionBar chat_id:int53 = Ok; + //@description Reports a chat to the Telegram moderators. Supported only for supergroups, channels, or private chats with bots, since other chats can't be checked by moderators @chat_id Chat identifier @reason The reason for reporting the chat @message_ids Identifiers of reported messages, if any reportChat chat_id:int53 reason:ChatReportReason message_ids:vector = Ok; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index d2bb1dd68f384eb51b0d9da07f207bc7473df4b5..de23e5c20018f4089ba945cec063b216403127db 100644 GIT binary patch delta 55 zcmV-70LcIB>j}v034pW#ILHBGw>iiGlV=$EIhdUja%F9Ac4b3oVRS)bbZKvHLSb^3 NP$&XKx6CgBAV#lC7Ht3k delta 25 hcmX@{hV#v9&W0_F7AF{!wp*THoSeR0!+=S_4FH|<3Sa;L diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 78e159a5d..e951dd7ea 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -3223,7 +3223,9 @@ class UpdatePeerSettingsQuery : public Td::ResultHandler { dialog_id_ = dialog_id; auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read); - CHECK(input_peer != nullptr); + if (input_peer == nullptr) { + return promise_.set_value(Unit()); + } if (is_spam_dialog) { send_query( @@ -6508,6 +6510,35 @@ void MessagesManager::change_dialog_report_spam_state(DialogId dialog_id, bool i change_dialog_report_spam_state_on_server(dialog_id, is_spam_dialog, 0, std::move(promise)); } +void MessagesManager::remove_dialog_action_bar(DialogId dialog_id, Promise &&promise) { + Dialog *d = get_dialog_force(dialog_id); + if (d == nullptr) { + return promise.set_error(Status::Error(3, "Chat not found")); + } + + if (!have_input_peer(dialog_id, AccessRights::Read)) { + return promise.set_error(Status::Error(3, "Can't access the chat")); + } + + if (!d->know_can_report_spam) { + return promise.set_error(Status::Error(3, "Can't update chat action bar")); + } + + if (!d->can_report_spam && !d->can_add_contact && !d->can_block_user && !d->can_share_phone_number && + !d->can_report_location) { + return promise.set_value(Unit()); + } + + d->can_report_spam = false; + d->can_add_contact = false; + d->can_block_user = false; + d->can_share_phone_number = false; + d->can_report_location = false; + on_dialog_updated(dialog_id, "remove_dialog_action_bar"); + + change_dialog_report_spam_state_on_server(dialog_id, false, 0, std::move(promise)); +} + class MessagesManager::ChangeDialogReportSpamStateOnServerLogEvent { public: DialogId dialog_id_; @@ -6551,8 +6582,8 @@ void MessagesManager::change_dialog_report_spam_state_on_server(DialogId dialog_ if (is_spam_dialog) { return td_->create_handler(std::move(promise))->send(dialog_id); } else { - promise.set_value(Unit()); - return; + auto user_id = td_->contacts_manager_->get_secret_chat_user_id(dialog_id.get_secret_chat_id()); + return td_->create_handler(std::move(promise))->send(DialogId(user_id), false); } case DialogType::None: default: diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index b0afe9a39..355441dcc 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -667,6 +667,8 @@ class MessagesManager : public Actor { void change_dialog_report_spam_state(DialogId dialog_id, bool is_spam_dialog, Promise &&promise); + void remove_dialog_action_bar(DialogId dialog_id, Promise &&promise); + void report_dialog(DialogId dialog_id, const tl_object_ptr &reason, const vector &message_ids, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index d6fbc837d..db99e7e32 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6688,6 +6688,12 @@ void Td::on_request(uint64 id, const td_api::changeChatReportSpamState &request) std::move(promise)); } +void Td::on_request(uint64 id, const td_api::removeChatActionBar &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + messages_manager_->remove_dialog_action_bar(DialogId(request.chat_id_), std::move(promise)); +} + void Td::on_request(uint64 id, td_api::reportChat &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index b57362b73..9b82aeebd 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -848,6 +848,8 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, const td_api::changeChatReportSpamState &request); + void on_request(uint64 id, const td_api::removeChatActionBar &request); + void on_request(uint64 id, td_api::reportChat &request); void on_request(uint64 id, td_api::getChatStatisticsUrl &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index de3061240..3e52b76b8 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3626,6 +3626,9 @@ class CliClient final : public Actor { std::tie(chat_id, is_spam_chat) = split(args); send_request(td_api::make_object(as_chat_id(chat_id), as_bool(is_spam_chat))); + } else if (op == "rcab") { + string chat_id = args; + send_request(td_api::make_object(as_chat_id(chat_id))); } else if (op == "rc") { string chat_id; string reason_str;