From 7327b673ded4614cd3d60dab75c52068eb9446d8 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 11 Oct 2019 04:17:46 +0300 Subject: [PATCH] Support action bar report in reportChat. GitOrigin-RevId: 2c85ca043c9615a27c1bdf46b7fd01ed98940699 --- td/generate/scheme/td_api.tl | 2 +- td/telegram/MessagesManager.cpp | 60 +++++++++++++++++++++++++++++---- td/telegram/MessagesManager.h | 2 ++ 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 4ed4259e5..6c6184d4a 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3901,7 +3901,7 @@ deleteAccount reason:string = 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 +//@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, or when the report is done from the chat action bar @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/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 8cb55fb5e..622e97fcc 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -6454,6 +6454,21 @@ void MessagesManager::repair_dialog_action_bar(DialogId dialog_id) { } } +void MessagesManager::hide_dialog_action_bar(Dialog *d) { + CHECK(d->dialog_id.get_type() != DialogType::SecretChat); + if (!d->can_report_spam && !d->can_add_contact && !d->can_block_user && !d->can_share_phone_number && + !d->can_report_location) { + return; + } + + 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; + send_update_chat_action_bar(d); +} + void MessagesManager::remove_dialog_action_bar(DialogId dialog_id, Promise &&promise) { Dialog *d = get_dialog_force(dialog_id); if (d == nullptr) { @@ -6464,6 +6479,17 @@ void MessagesManager::remove_dialog_action_bar(DialogId dialog_id, Promise return promise.set_error(Status::Error(3, "Can't access the chat")); } + if (dialog_id.get_type() == DialogType::SecretChat) { + dialog_id = DialogId(td_->contacts_manager_->get_secret_chat_user_id(dialog_id.get_secret_chat_id())); + d = get_dialog_force(dialog_id); + if (d == nullptr) { + return promise.set_error(Status::Error(3, "Chat with the user 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")); } @@ -6473,12 +6499,7 @@ void MessagesManager::remove_dialog_action_bar(DialogId dialog_id, Promise 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"); + hide_dialog_action_bar(d); change_dialog_report_spam_state_on_server(dialog_id, false, 0, std::move(promise)); } @@ -6568,7 +6589,34 @@ void MessagesManager::report_dialog(DialogId dialog_id, const tl_object_ptrcan_report_spam; + if (reason->get_id() == td_api::chatReportReasonSpam::ID && message_ids.empty()) { + if (dialog_id.get_type() == DialogType::SecretChat) { + auto user_dialog_id = DialogId(td_->contacts_manager_->get_secret_chat_user_id(dialog_id.get_secret_chat_id())); + user_d = get_dialog_force(user_dialog_id); + if (user_d == nullptr) { + return promise.set_error(Status::Error(3, "Chat with the user not found")); + } + + is_dialog_spam_report = user_d->know_can_report_spam; + can_report_spam = user_d->can_report_spam; + } else { + is_dialog_spam_report = d->know_can_report_spam; + } + } + + if (is_dialog_spam_report && can_report_spam) { + hide_dialog_action_bar(user_d); + return change_dialog_report_spam_state_on_server(dialog_id, true, 0, std::move(promise)); + } + if (!can_report_dialog(dialog_id)) { + if (is_dialog_spam_report) { + return promise.set_value(Unit()); + } + return promise.set_error(Status::Error(3, "Chat can't be reported")); } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 447917b0d..c07a7583a 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1809,6 +1809,8 @@ class MessagesManager : public Actor { void send_update_chat_action_bar(const Dialog *d); + void hide_dialog_action_bar(Dialog *d); + tl_object_ptr get_message_object(DialogId dialog_id, const Message *m, bool for_event_log = false) const;