diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 7c748859e..a5f0c8283 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -5392,8 +5392,8 @@ toggleSupergroupIsAllHistoryAvailable supergroup_id:int53 is_all_history_availab //@description Upgrades supergroup to a broadcast group; requires owner privileges in the supergroup @supergroup_id Identifier of the supergroup toggleSupergroupIsBroadcastGroup supergroup_id:int53 = Ok; -//@description Reports some messages from a user in a supergroup as spam; requires administrator rights in the supergroup @supergroup_id Supergroup identifier @user_id User identifier @message_ids Identifiers of messages sent in the supergroup by the user. This list must be non-empty -reportSupergroupSpam supergroup_id:int53 user_id:int53 message_ids:vector = Ok; +//@description Reports some messages from a message sender in a supergroup as spam; requires administrator rights in the supergroup @supergroup_id Supergroup identifier @message_ids Identifiers of messages sent in the supergroup. All messages must be sent by the same sender. This list must be non-empty +reportSupergroupSpam supergroup_id:int53 message_ids:vector = Ok; //@description Returns information about members or banned users in a supergroup or channel. Can be used only if supergroupFullInfo.can_get_members == true; additionally, administrator privileges may be required for some filters @supergroup_id Identifier of the supergroup or channel //@filter The type of users to return; pass null to use supergroupMembersFilterRecent @offset Number of users to skip @limit The maximum number of users be returned; up to 200 diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 4b0f02ddb..f52749ab6 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -1085,13 +1085,13 @@ class ReportChannelSpamQuery final : public Td::ResultHandler { explicit ReportChannelSpamQuery(Promise &&promise) : promise_(std::move(promise)) { } - void send(ChannelId channel_id, UserId user_id, const vector &message_ids) { + void send(ChannelId channel_id, DialogId sender_dialog_id, const vector &message_ids) { channel_id_ = channel_id; auto input_channel = td_->contacts_manager_->get_input_channel(channel_id); CHECK(input_channel != nullptr); - auto input_peer = td_->contacts_manager_->get_input_peer_user(user_id, AccessRights::Know); + auto input_peer = td_->messages_manager_->get_input_peer(sender_dialog_id, AccessRights::Know); CHECK(input_peer != nullptr); send_query(G()->net_query_creator().create(telegram_api::channels_reportSpam( @@ -1105,13 +1105,13 @@ class ReportChannelSpamQuery final : public Td::ResultHandler { } bool result = result_ptr.move_as_ok(); - LOG_IF(INFO, !result) << "Report spam has failed"; + LOG_IF(INFO, !result) << "Report spam has failed in " << channel_id_; promise_.set_value(Unit()); } void on_error(Status status) final { - td_->contacts_manager_->on_get_channel_error(channel_id_, status, "ReportChannelSpamQuery"); + // td_->contacts_manager_->on_get_channel_error(channel_id_, status, "ReportChannelSpamQuery"); promise_.set_error(std::move(status)); } }; @@ -6554,7 +6554,7 @@ void ContactsManager::send_load_async_graph_query(DcId dc_id, string token, int6 td_->create_handler(std::move(promise))->send(token, x, dc_id); } -void ContactsManager::report_channel_spam(ChannelId channel_id, UserId user_id, const vector &message_ids, +void ContactsManager::report_channel_spam(ChannelId channel_id, const vector &message_ids, Promise &&promise) { auto c = get_channel(channel_id); if (c == nullptr) { @@ -6564,17 +6564,11 @@ void ContactsManager::report_channel_spam(ChannelId channel_id, UserId user_id, return promise.set_error(Status::Error(400, "Spam can be reported only in supergroups")); } - if (!have_input_user(user_id)) { - return promise.set_error(Status::Error(400, "Have no access to the user")); - } - if (user_id == get_my_id()) { - return promise.set_error(Status::Error(400, "Can't report self")); - } - if (message_ids.empty()) { return promise.set_error(Status::Error(400, "Message list is empty")); } + DialogId sender_dialog_id; vector server_message_ids; for (auto &message_id : message_ids) { if (message_id.is_valid_scheduled()) { @@ -6585,15 +6579,38 @@ void ContactsManager::report_channel_spam(ChannelId channel_id, UserId user_id, return promise.set_error(Status::Error(400, "Message not found")); } - if (message_id.is_server()) { - server_message_ids.push_back(message_id); + if (!message_id.is_server()) { + continue; } + + auto current_sender_dialog_id = td_->messages_manager_->get_message_sender({DialogId(channel_id), message_id}); + if (!current_sender_dialog_id.is_valid()) { + continue; + } + if (sender_dialog_id.is_valid()) { + if (current_sender_dialog_id != sender_dialog_id) { + return promise.set_error(Status::Error(400, "All messages nust be from the same sender")); + } + } else { + sender_dialog_id = current_sender_dialog_id; + } + + server_message_ids.push_back(message_id); } if (server_message_ids.empty()) { return promise.set_value(Unit()); } + CHECK(sender_dialog_id.is_valid()); - td_->create_handler(std::move(promise))->send(channel_id, user_id, server_message_ids); + if (!td_->messages_manager_->have_input_peer(sender_dialog_id, AccessRights::Know)) { + return promise.set_error(Status::Error(400, "Have no access to the user")); + } + if (sender_dialog_id == DialogId(get_my_id())) { + return promise.set_error(Status::Error(400, "Can't report self")); + } + + td_->create_handler(std::move(promise)) + ->send(channel_id, sender_dialog_id, server_message_ids); } void ContactsManager::delete_chat(ChatId chat_id, Promise &&promise) { diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index bb1fd395a..bf71e2c46 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -339,8 +339,7 @@ class ContactsManager final : public Actor { void set_channel_slow_mode_delay(DialogId dialog_id, int32 slow_mode_delay, Promise &&promise); - void report_channel_spam(ChannelId channel_id, UserId user_id, const vector &message_ids, - Promise &&promise); + void report_channel_spam(ChannelId channel_id, const vector &message_ids, Promise &&promise); void delete_dialog(DialogId dialog_id, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 7f7083b10..3930f3012 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5454,10 +5454,8 @@ void Td::on_request(uint64 id, const td_api::deleteMessages &request) { void Td::on_request(uint64 id, const td_api::deleteChatMessagesBySender &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); - TRY_RESULT_PROMISE(promise, participant_dialog_id, - get_message_sender_dialog_id(this, request.sender_id_, false, false)); - messages_manager_->delete_dialog_messages_by_sender(DialogId(request.chat_id_), participant_dialog_id, - std::move(promise)); + TRY_RESULT_PROMISE(promise, sender_dialog_id, get_message_sender_dialog_id(this, request.sender_id_, false, false)); + messages_manager_->delete_dialog_messages_by_sender(DialogId(request.chat_id_), sender_dialog_id, std::move(promise)); } void Td::on_request(uint64 id, const td_api::deleteChatMessagesByDate &request) { @@ -6846,7 +6844,7 @@ void Td::on_request(uint64 id, const td_api::toggleSupergroupIsBroadcastGroup &r void Td::on_request(uint64 id, const td_api::reportSupergroupSpam &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); - contacts_manager_->report_channel_spam(ChannelId(request.supergroup_id_), UserId(request.user_id_), + contacts_manager_->report_channel_spam(ChannelId(request.supergroup_id_), MessagesManager::get_message_ids(request.message_ids_), std::move(promise)); } diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 2fb10af44..291914662 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4339,13 +4339,12 @@ class CliClient final : public Actor { send_request(td_api::make_object(as_chat_id(chat_id), as_message_id(message_id), as_button_id(button_id), op == "glua")); } - } else if (op == "rsgs" || op == "rchs") { + } else if (op == "rsgs") { string supergroup_id; - string user_id; string message_ids; - get_args(args, supergroup_id, user_id, message_ids); + get_args(args, supergroup_id, message_ids); send_request(td_api::make_object(as_supergroup_id(supergroup_id), - as_user_id(user_id), as_message_ids(message_ids))); + as_message_ids(message_ids))); } else if (op == "gdiff") { send_request(td_api::make_object()); } else if (op == "dproxy") {