Implemented deleteMessages method

parameters:
- chat_id the chat_id of the supergroup or channel
- start first message id to delete
- end last message id to delete
the method will always return `true` as a result, even if the messages 
cannot be deleted
this method does not work on private chat or normal groups
it is not suggested to delete more than 200 messages per call
This commit is contained in:
Giuseppe Marino 2020-11-11 17:07:36 +01:00
parent 0c5a139146
commit cb7dcb5c0b
No known key found for this signature in database
GPG Key ID: 2BC70C5463357449

View File

@ -7453,7 +7453,47 @@ td::Status Client::process_get_participants_query(PromisedQueryPtr &query) {
} }
td::Status Client::process_delete_messages_query(PromisedQueryPtr &query) { td::Status Client::process_delete_messages_query(PromisedQueryPtr &query) {
answer_query(td::JsonFalse(), std::move(query), "Not implemented"); auto chat_id = query->arg("chat_id");
if (chat_id.empty()) {
return Status::Error(400, "Chat identifier is not specified");
}
auto start = as_client_message_id(get_message_id(query.get(), "start"));
auto end = as_client_message_id(get_message_id(query.get(), "end"));
if (start == 0 || end == 0) {
return Status::Error(400, "Message identifier is not specified");
}
if (start >= end) {
return Status::Error(400, "Initial message identifier is not lower than last message identifier");
}
check_chat(chat_id, AccessRights::Write, std::move(query), [this, start, end](int64 chat_id, PromisedQueryPtr query) {
if (get_chat_type(chat_id) != ChatType::Supergroup) {
return fail_query(400, "Bad Request: method is available only for supergroups", std::move(query));
}
td::vector<td::int64> ids;
ids.reserve(200);
for (td::int32 i = start; i <= end; i++) {
ids.push_back(as_tdlib_message_id(i));
if (ids.size() == 200) {
send_request(make_object<td_api::deleteMessages>(chat_id, std::move(ids), true),
std::make_unique<TdOnOkCallback>());
ids.clear();
}
}
if (ids.size() != 0) {
send_request(make_object<td_api::deleteMessages>(chat_id, std::move(ids), true),
std::make_unique<TdOnOkCallback>());
}
answer_query(td::JsonTrue(), std::move(query));
});
return Status::OK(); return Status::OK();
} }