From 4238f28a19504b0f8803de7703e1cc2ee06d05e3 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 24 Aug 2018 01:02:59 +0300 Subject: [PATCH] Add td_api::getPreferredCountryLanguage. GitOrigin-RevId: a7abb6ac1b702292216fdf046b07af92fce99d65 --- td/generate/scheme/td_api.tl | 8 +++- td/generate/scheme/td_api.tlo | Bin 133696 -> 133812 bytes td/telegram/LanguagePackManager.cpp | 2 +- td/telegram/SecureManager.cpp | 63 ++++++++++++++++++++++++++++ td/telegram/SecureManager.h | 2 + td/telegram/Td.cpp | 8 ++++ td/telegram/Td.h | 2 + td/telegram/cli.cpp | 9 ++-- 8 files changed, 87 insertions(+), 7 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 29939bd7..05a98944 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1722,8 +1722,8 @@ languagePackString key:string value:LanguagePackStringValue = LanguagePackString //@description Contains a list of language pack strings @strings A list of language pack strings languagePackStrings strings:vector = LanguagePackStrings; -//@description Contains information about a language @code Language code @name Language name @native_name Language native name @local_key_count Total number of locally available non-deleted keys from the language -languageInfo code:string name:string native_name:string key_count:int32 = LanguageInfo; +//@description Contains information about a language @code Language code @name Language name @native_name Language native name @local_string_count Total number of locally available non-deleted strings from the language +languageInfo code:string name:string native_name:string local_string_count:int32 = LanguageInfo; //@description Contains information about a language pack @languages List of available languages languagePack languages:vector = LanguagePack; @@ -3238,6 +3238,10 @@ deletePassportElement type:PassportElementType = Ok; setPassportElementErrors user_id:int32 errors:vector = Ok; +//@description Returns an IETF language tag of the language preferred in the country, which should be used to fill native fields in Telegram Passport personal details. Returns a 404 error if unknown @country_code A two-letter ISO 3166-1 alpha-2 country code +getPreferredCountryLanguage country_code:string = Text; + + //@description Sends a code to verify a phone number to be added to a user's Telegram Passport //@phone_number The phone number of the user, in international format @allow_flash_call Pass true if the authentication code may be sent via flash call to the specified phone number @is_current_phone_number Pass true if the phone number is used on the current device. Ignored if allow_flash_call is false sendPhoneNumberVerificationCode phone_number:string allow_flash_call:Bool is_current_phone_number:Bool = AuthenticationCodeInfo; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index f714146f90305c82d290a500a903f5d08e71c65b..2db87bff798659fc90a6865c3ee11c8ed3ea876e 100644 GIT binary patch delta 181 zcmX>wg=5Q9jtx8bS?r@8Oy0bQKVZ2mh{cnWn3rCfn4apHmzK}KzyK1vc}&QMWjbR! zqw;hCSw@w~1>044g>v$f6LaE=ONuh{(x>+-GfGc>puqt)Z1REa5fD>lb_DEY)ZLz2 z${6gTdF^!43F-9Il7OPrwA7-a)D-9Z(!7$QN*}0&Ga|~AKsGT>wp7-heqbG=#P$O_ Q84s9&joRMwfpL!{04_dAT>t<8 delta 136 zcmdlomE*t^jtx8bS(;q}-8b*y4_Gb>V)5i8=B1Y=rl)%5rR6g)Fo48v9ux9mnI726 zs65%>1?zNKSw{KE1>03vIkQtME`Q4kOS!hRGXu*-sBBV-(o#^N}$_5&+pmF3tb| diff --git a/td/telegram/LanguagePackManager.cpp b/td/telegram/LanguagePackManager.cpp index 50142955..250f1408 100644 --- a/td/telegram/LanguagePackManager.cpp +++ b/td/telegram/LanguagePackManager.cpp @@ -573,7 +573,7 @@ void LanguagePackManager::on_get_languages(vectorlanguages_) { auto language = add_language(database_, language_pack, language_info->code_); - language_info->key_count_ = language->key_count_; + language_info->local_string_count_ = language->key_count_; } promise.set_value(std::move(results)); diff --git a/td/telegram/SecureManager.cpp b/td/telegram/SecureManager.cpp index f8f1c3a5..b92ca27c 100644 --- a/td/telegram/SecureManager.cpp +++ b/td/telegram/SecureManager.cpp @@ -886,6 +886,60 @@ void SecureManager::get_secure_value(std::string password, SecureValueType type, .release(); } +class GetPassportConfig : public NetQueryCallback { + public: + GetPassportConfig(ActorShared parent, string country_code, + Promise> promise) + : parent_(std::move(parent)), country_code_(std::move(country_code)), promise_(std::move(promise)) { + } + + private: + ActorShared parent_; + string country_code_; + Promise> promise_; + + void start_up() override { + auto query = G()->net_query_creator().create(create_storer(telegram_api::help_getPassportConfig(0))); + G()->net_query_dispatcher().dispatch_with_callback(std::move(query), actor_shared(this)); + } + + void on_result(NetQueryPtr query) override { + auto r_result = fetch_result(std::move(query)); + if (r_result.is_error()) { + promise_.set_error(r_result.move_as_error()); + stop(); + return; + } + + auto config = r_result.move_as_ok(); + switch (config->get_id()) { + case telegram_api::help_passportConfigNotModified::ID: + promise_.set_error(Status::Error(500, "Wrong server response")); + break; + case telegram_api::help_passportConfig::ID: { + const string &data = + static_cast(config.get())->countries_langs_->data_; + auto begin_pos = data.find((PSLICE() << '"' << country_code_ << "\":\"").c_str()); + if (begin_pos == string::npos) { + promise_.set_value(nullptr); + break; + } + + begin_pos += 4 + country_code_.size(); + auto end_pos = data.find('"', begin_pos); + if (end_pos == string::npos) { + return promise_.set_error(Status::Error(500, "Wrong server response")); + } + promise_.set_value(td_api::make_object(data.substr(begin_pos, end_pos - begin_pos))); + break; + } + default: + UNREACHABLE(); + } + stop(); + } +}; + void SecureManager::on_get_secure_value(SecureValueWithCredentials value) { auto type = value.value.type; secure_value_cache_[type] = std::move(value); @@ -1135,6 +1189,15 @@ void SecureManager::send_passport_authorization_form(int32 authorization_form_id send_with_promise(std::move(query), std::move(new_promise)); } +void SecureManager::get_preferred_country_code(string country_code, Promise> promise) { + refcnt_++; + for (auto &c : country_code) { + c = to_upper(c); + } + create_actor("GetPassportConfig", actor_shared(this), std::move(country_code), std::move(promise)) + .release(); +} + void SecureManager::hangup() { container_.for_each( [](auto id, Promise &promise) { promise.set_error(Status::Error(500, "Request aborted")); }); diff --git a/td/telegram/SecureManager.h b/td/telegram/SecureManager.h index 65d562b1..b7f00762 100644 --- a/td/telegram/SecureManager.h +++ b/td/telegram/SecureManager.h @@ -50,6 +50,8 @@ class SecureManager : public NetQueryCallback { void send_passport_authorization_form(int32 authorization_form_id, std::vector types, Promise<> promise); + void get_preferred_country_code(string country_code, Promise> promise); + private: ActorShared<> parent_; int32 refcnt_{1}; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index bad98a25..1e30b62e 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6424,6 +6424,14 @@ void Td::on_request(uint64 id, td_api::setPassportElementErrors &request) { std::move(request.errors_), std::move(promise)); } +void Td::on_request(uint64 id, td_api::getPreferredCountryLanguage &request) { + CHECK_IS_USER(); + CLEAN_INPUT_STRING(request.country_code_); + CREATE_REQUEST_PROMISE(); + send_closure(secure_manager_, &SecureManager::get_preferred_country_code, std::move(request.country_code_), + std::move(promise)); +} + void Td::on_request(uint64 id, td_api::sendPhoneNumberVerificationCode &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.phone_number_); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 6efec72b..0c992d26 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -813,6 +813,8 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, td_api::setPassportElementErrors &request); + void on_request(uint64 id, td_api::getPreferredCountryLanguage &request); + void on_request(uint64 id, td_api::sendPhoneNumberVerificationCode &request); void on_request(uint64 id, const td_api::resendPhoneNumberVerificationCode &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 7083c9eb..c88e7a98 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -608,10 +608,9 @@ class CliClient final : public Actor { } void on_error(uint64 id, tl_object_ptr error) { - auto current_verbosity_level = GET_VERBOSITY_LEVEL(); - SET_VERBOSITY_LEVEL(VERBOSITY_NAME(INFO)); - LOG(INFO) << "on_error [id=" << id << "] " << to_string(error); - SET_VERBOSITY_LEVEL(current_verbosity_level); + if (id > 0 && GET_VERBOSITY_LEVEL() < VERBOSITY_NAME(td_requests)) { + LOG(ERROR) << "on_error [id=" << id << "] " << to_string(error); + } } void on_closed() { @@ -1288,6 +1287,8 @@ class CliClient final : public Actor { std::tie(id, types) = split(args); send_request(make_tl_object(to_integer(id), as_passport_element_types(types))); + } else if (op == "gpcl") { + send_request(make_tl_object(args)); } else if (op == "spnvc" || op == "SendPhoneNumberVerificationCode") { send_request(make_tl_object(args, false, false)); } else if (op == "cpnvc" || op == "CheckPhoneNumberVerificationCode") {