diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index f3c75a350..d242063ca 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -32,10 +32,10 @@ ok = Ok; //@use_secret_chats If set to true, support for secret chats will be enabled //@api_id Application identifier for Telegram API access, which can be obtained at https://my.telegram.org //@api_hash Application identifier hash for Telegram API access, which can be obtained at https://my.telegram.org -//@system_language_code IETF language tag of the user's operating system language -//@device_model Model of the device the application is being run on -//@system_version Version of the operating system the application is being run on -//@application_version Application version +//@system_language_code IETF language tag of the user's operating system language; must be non-empty +//@device_model Model of the device the application is being run on; must be non-empty +//@system_version Version of the operating system the application is being run on; must be non-empty +//@application_version Application version; must be non-empty //@enable_storage_optimizer If set to true, old files will automatically be deleted //@ignore_file_names If set to true, original file names will be ignored. Otherwise, downloaded files will be saved under names as close as possible to the original name tdlibParameters use_test_dc:Bool database_directory:string files_directory:string use_file_database:Bool use_chat_info_database:Bool use_message_database:Bool use_secret_chats:Bool api_id:int32 api_hash:string system_language_code:string device_model:string system_version:string application_version:string enable_storage_optimizer:Bool ignore_file_names:Bool = TdlibParameters; @@ -2637,7 +2637,7 @@ pinSupergroupMessage supergroup_id:int32 message_id:int53 disable_notification:B //@description Removes the pinned message from a supergroup or channel; requires appropriate administrator rights in the supergroup or channel @supergroup_id Identifier of the supergroup or channel unpinSupergroupMessage supergroup_id:int32 = Ok; -//@description Reports some messages from a user in a supergroup as spam @supergroup_id Supergroup identifier @user_id User identifier @message_ids Identifiers of messages sent in the supergroup by the user. This list should be non-empty +//@description Reports some messages from a user in a supergroup as spam @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:int32 user_id:int32 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 diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 06636da1a..4a030282d 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3694,7 +3694,8 @@ void Td::request(uint64 id, tl_object_ptr function) { case State::WaitParameters: { switch (function->get_id()) { case td_api::getAuthorizationState::ID: - return send_result(id, td_api::make_object()); + return send_closure(actor_id(this), &Td::send_result, id, + td_api::make_object()); case td_api::setTdlibParameters::ID: return answer_ok_query( id, set_parameters(std::move(move_tl_object_as(function)->parameters_))); @@ -3707,8 +3708,9 @@ void Td::request(uint64 id, tl_object_ptr function) { string encryption_key; switch (function->get_id()) { case td_api::getAuthorizationState::ID: - return send_result( - id, td_api::make_object(encryption_info_.is_encrypted)); + return send_closure( + actor_id(this), &Td::send_result, id, + td_api::make_object(encryption_info_.is_encrypted)); case td_api::checkDatabaseEncryptionKey::ID: { auto check_key = move_tl_object_as(function); encryption_key = std::move(check_key->encryption_key_); @@ -3731,9 +3733,11 @@ void Td::request(uint64 id, tl_object_ptr function) { case State::Close: { if (function->get_id() == td_api::getAuthorizationState::ID) { if (close_flag_ == 5) { - return send_result(id, td_api::make_object()); + return send_closure(actor_id(this), &Td::send_result, id, + td_api::make_object()); } else { - return send_result(id, td_api::make_object()); + return send_closure(actor_id(this), &Td::send_result, id, + td_api::make_object()); } } return send_error_raw(id, 401, "Unauthorized"); @@ -3909,6 +3913,10 @@ void Td::on_authorization_lost() { destroy(); } +static td_api::object_ptr make_error(int32 code, CSlice error) { + return td_api::make_object(code, error.str()); +} + void Td::start_up() { always_wait_for_mailbox(); @@ -4080,9 +4088,9 @@ void Td::clear() { while (!request_set_.empty()) { uint64 id = *request_set_.begin(); if (destroy_flag_) { - send_error_raw(id, 401, "Unauthorized"); + send_error_impl(id, make_error(401, "Unauthorized")); } else { - send_error_raw(id, 500, "Internal Server Error: closing"); + send_error_impl(id, make_error(500, "Internal Server Error: closing")); } } if (is_online_) { @@ -4460,14 +4468,8 @@ void Td::send_error(uint64 id, Status error) { error.ignore(); } -namespace { -auto create_error_raw(int32 code, CSlice error) { - return make_tl_object(code, error.str()); -} -} // namespace - void Td::send_error_raw(uint64 id, int32 code, CSlice error) { - send_error_impl(id, create_error_raw(code, error)); + send_closure(actor_id(this), &Td::send_error_impl, id, make_error(code, error)); } void Td::answer_ok_query(uint64 id, Status status) { @@ -4587,10 +4589,22 @@ Status Td::set_parameters(td_api::object_ptr parameters MtprotoHeader::Options options; options.api_id = parameters->api_id_; - options.system_language_code = parameters->system_language_code_; - options.device_model = parameters->device_model_; - options.system_version = parameters->system_version_; - options.application_version = parameters->application_version_; + options.system_language_code = trim(parameters->system_language_code_); + options.device_model = trim(parameters->device_model_); + options.system_version = trim(parameters->system_version_); + options.application_version = trim(parameters->application_version_); + if (options.system_language_code.empty()) { + return Status::Error(400, "System language code must be non-empty"); + } + if (options.device_model.empty()) { + return Status::Error(400, "Device model must be non-empty"); + } + if (options.system_version.empty()) { + return Status::Error(400, "System version must be non-empty"); + } + if (options.application_version.empty()) { + return Status::Error(400, "Application version must be non-empty"); + } if (options.api_id != 21724) { options.application_version += ", TDLib "; options.application_version += tdlib_version; @@ -4598,8 +4612,9 @@ Status Td::set_parameters(td_api::object_ptr parameters G()->set_mtproto_header(std::make_unique(options)); state_ = State::Decrypt; - send_update(td_api::make_object( - td_api::make_object(encryption_info_.is_encrypted))); + send_closure(actor_id(this), &Td::send_update, + td_api::make_object( + td_api::make_object(encryption_info_.is_encrypted))); return Status::OK(); } @@ -6657,12 +6672,12 @@ void Td::on_request(uint64 id, const td_api::getFileExtension &request) { template td_api::object_ptr Td::do_static_request(const T &) { - return create_error_raw(400, "Function can't be executed synchronously"); + return make_error(400, "Function can't be executed synchronously"); } td_api::object_ptr Td::do_static_request(const td_api::getTextEntities &request) { if (!check_utf8(request.text_)) { - return create_error_raw(400, "Text must be encoded in UTF-8"); + return make_error(400, "Text must be encoded in UTF-8"); } auto text_entities = find_entities(request.text_, false); return make_tl_object(get_text_entities_object(text_entities)); @@ -6670,10 +6685,10 @@ td_api::object_ptr Td::do_static_request(const td_api::getTextEn td_api::object_ptr Td::do_static_request(td_api::parseTextEntities &request) { if (!check_utf8(request.text_)) { - return create_error_raw(400, "Text must be encoded in UTF-8"); + return make_error(400, "Text must be encoded in UTF-8"); } if (request.parse_mode_ == nullptr) { - return create_error_raw(400, "Parse mode must be non-empty"); + return make_error(400, "Parse mode must be non-empty"); } Result> r_entities; @@ -6689,7 +6704,7 @@ td_api::object_ptr Td::do_static_request(td_api::parseTextEntiti break; } if (r_entities.is_error()) { - return create_error_raw(400, PSLICE() << "Can't parse entities: " << r_entities.error().message()); + return make_error(400, PSLICE() << "Can't parse entities: " << r_entities.error().message()); } return make_tl_object(std::move(request.text_), get_text_entities_object(r_entities.ok()));