Remove user_id from reportSupergroupSpam.

This commit is contained in:
levlam 2021-11-19 17:12:38 +03:00
parent 04be7955a7
commit 993a9e24c4
5 changed files with 41 additions and 28 deletions

View File

@ -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<int53> = 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<int53> = 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

View File

@ -1085,13 +1085,13 @@ class ReportChannelSpamQuery final : public Td::ResultHandler {
explicit ReportChannelSpamQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(ChannelId channel_id, UserId user_id, const vector<MessageId> &message_ids) {
void send(ChannelId channel_id, DialogId sender_dialog_id, const vector<MessageId> &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<LoadAsyncGraphQuery>(std::move(promise))->send(token, x, dc_id);
}
void ContactsManager::report_channel_spam(ChannelId channel_id, UserId user_id, const vector<MessageId> &message_ids,
void ContactsManager::report_channel_spam(ChannelId channel_id, const vector<MessageId> &message_ids,
Promise<Unit> &&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<MessageId> 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<ReportChannelSpamQuery>(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<ReportChannelSpamQuery>(std::move(promise))
->send(channel_id, sender_dialog_id, server_message_ids);
}
void ContactsManager::delete_chat(ChatId chat_id, Promise<Unit> &&promise) {

View File

@ -339,8 +339,7 @@ class ContactsManager final : public Actor {
void set_channel_slow_mode_delay(DialogId dialog_id, int32 slow_mode_delay, Promise<Unit> &&promise);
void report_channel_spam(ChannelId channel_id, UserId user_id, const vector<MessageId> &message_ids,
Promise<Unit> &&promise);
void report_channel_spam(ChannelId channel_id, const vector<MessageId> &message_ids, Promise<Unit> &&promise);
void delete_dialog(DialogId dialog_id, Promise<Unit> &&promise);

View File

@ -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));
}

View File

@ -4339,13 +4339,12 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::getLoginUrl>(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<td_api::reportSupergroupSpam>(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<td_api::testGetDifference>());
} else if (op == "dproxy") {