Add td_api::getPreferredCountryLanguage.

GitOrigin-RevId: a7abb6ac1b702292216fdf046b07af92fce99d65
This commit is contained in:
levlam 2018-08-24 01:02:59 +03:00
parent 06d04c8652
commit 4238f28a19
8 changed files with 87 additions and 7 deletions

View File

@ -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 //@description Contains a list of language pack strings @strings A list of language pack strings
languagePackStrings strings:vector<languagePackString> = LanguagePackStrings; languagePackStrings strings:vector<languagePackString> = 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 //@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 key_count:int32 = LanguageInfo; 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 //@description Contains information about a language pack @languages List of available languages
languagePack languages:vector<languageInfo> = LanguagePack; languagePack languages:vector<languageInfo> = LanguagePack;
@ -3238,6 +3238,10 @@ deletePassportElement type:PassportElementType = Ok;
setPassportElementErrors user_id:int32 errors:vector<inputPassportElementError> = Ok; setPassportElementErrors user_id:int32 errors:vector<inputPassportElementError> = 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 //@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 //@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; sendPhoneNumberVerificationCode phone_number:string allow_flash_call:Bool is_current_phone_number:Bool = AuthenticationCodeInfo;

Binary file not shown.

View File

@ -573,7 +573,7 @@ void LanguagePackManager::on_get_languages(vector<tl_object_ptr<telegram_api::la
for (auto &language_info : results->languages_) { for (auto &language_info : results->languages_) {
auto language = add_language(database_, language_pack, language_info->code_); 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)); promise.set_value(std::move(results));

View File

@ -886,6 +886,60 @@ void SecureManager::get_secure_value(std::string password, SecureValueType type,
.release(); .release();
} }
class GetPassportConfig : public NetQueryCallback {
public:
GetPassportConfig(ActorShared<SecureManager> parent, string country_code,
Promise<td_api::object_ptr<td_api::text>> promise)
: parent_(std::move(parent)), country_code_(std::move(country_code)), promise_(std::move(promise)) {
}
private:
ActorShared<SecureManager> parent_;
string country_code_;
Promise<td_api::object_ptr<td_api::text>> 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<telegram_api::help_getPassportConfig>(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<const telegram_api::help_passportConfig *>(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<td_api::text>(data.substr(begin_pos, end_pos - begin_pos)));
break;
}
default:
UNREACHABLE();
}
stop();
}
};
void SecureManager::on_get_secure_value(SecureValueWithCredentials value) { void SecureManager::on_get_secure_value(SecureValueWithCredentials value) {
auto type = value.value.type; auto type = value.value.type;
secure_value_cache_[type] = std::move(value); 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)); send_with_promise(std::move(query), std::move(new_promise));
} }
void SecureManager::get_preferred_country_code(string country_code, Promise<td_api::object_ptr<td_api::text>> promise) {
refcnt_++;
for (auto &c : country_code) {
c = to_upper(c);
}
create_actor<GetPassportConfig>("GetPassportConfig", actor_shared(this), std::move(country_code), std::move(promise))
.release();
}
void SecureManager::hangup() { void SecureManager::hangup() {
container_.for_each( container_.for_each(
[](auto id, Promise<NetQueryPtr> &promise) { promise.set_error(Status::Error(500, "Request aborted")); }); [](auto id, Promise<NetQueryPtr> &promise) { promise.set_error(Status::Error(500, "Request aborted")); });

View File

@ -50,6 +50,8 @@ class SecureManager : public NetQueryCallback {
void send_passport_authorization_form(int32 authorization_form_id, std::vector<SecureValueType> types, void send_passport_authorization_form(int32 authorization_form_id, std::vector<SecureValueType> types,
Promise<> promise); Promise<> promise);
void get_preferred_country_code(string country_code, Promise<td_api::object_ptr<td_api::text>> promise);
private: private:
ActorShared<> parent_; ActorShared<> parent_;
int32 refcnt_{1}; int32 refcnt_{1};

View File

@ -6424,6 +6424,14 @@ void Td::on_request(uint64 id, td_api::setPassportElementErrors &request) {
std::move(request.errors_), std::move(promise)); 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) { void Td::on_request(uint64 id, td_api::sendPhoneNumberVerificationCode &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CLEAN_INPUT_STRING(request.phone_number_); CLEAN_INPUT_STRING(request.phone_number_);

View File

@ -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::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, td_api::sendPhoneNumberVerificationCode &request);
void on_request(uint64 id, const td_api::resendPhoneNumberVerificationCode &request); void on_request(uint64 id, const td_api::resendPhoneNumberVerificationCode &request);

View File

@ -608,10 +608,9 @@ class CliClient final : public Actor {
} }
void on_error(uint64 id, tl_object_ptr<td_api::error> error) { void on_error(uint64 id, tl_object_ptr<td_api::error> error) {
auto current_verbosity_level = GET_VERBOSITY_LEVEL(); if (id > 0 && GET_VERBOSITY_LEVEL() < VERBOSITY_NAME(td_requests)) {
SET_VERBOSITY_LEVEL(VERBOSITY_NAME(INFO)); LOG(ERROR) << "on_error [id=" << id << "] " << to_string(error);
LOG(INFO) << "on_error [id=" << id << "] " << to_string(error); }
SET_VERBOSITY_LEVEL(current_verbosity_level);
} }
void on_closed() { void on_closed() {
@ -1288,6 +1287,8 @@ class CliClient final : public Actor {
std::tie(id, types) = split(args); std::tie(id, types) = split(args);
send_request(make_tl_object<td_api::sendPassportAuthorizationForm>(to_integer<int32>(id), send_request(make_tl_object<td_api::sendPassportAuthorizationForm>(to_integer<int32>(id),
as_passport_element_types(types))); as_passport_element_types(types)));
} else if (op == "gpcl") {
send_request(make_tl_object<td_api::getPreferredCountryLanguage>(args));
} else if (op == "spnvc" || op == "SendPhoneNumberVerificationCode") { } else if (op == "spnvc" || op == "SendPhoneNumberVerificationCode") {
send_request(make_tl_object<td_api::sendPhoneNumberVerificationCode>(args, false, false)); send_request(make_tl_object<td_api::sendPhoneNumberVerificationCode>(args, false, false));
} else if (op == "cpnvc" || op == "CheckPhoneNumberVerificationCode") { } else if (op == "cpnvc" || op == "CheckPhoneNumberVerificationCode") {