Add td_api::getPreferredCountryLanguage.
GitOrigin-RevId: a7abb6ac1b702292216fdf046b07af92fce99d65
This commit is contained in:
parent
06d04c8652
commit
4238f28a19
@ -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<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
|
||||
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<languageInfo> = LanguagePack;
|
||||
@ -3238,6 +3238,10 @@ deletePassportElement type:PassportElementType = 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
|
||||
//@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;
|
||||
|
Binary file not shown.
@ -573,7 +573,7 @@ void LanguagePackManager::on_get_languages(vector<tl_object_ptr<telegram_api::la
|
||||
|
||||
for (auto &language_info : results->languages_) {
|
||||
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));
|
||||
|
@ -886,6 +886,60 @@ void SecureManager::get_secure_value(std::string password, SecureValueType type,
|
||||
.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) {
|
||||
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<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() {
|
||||
container_.for_each(
|
||||
[](auto id, Promise<NetQueryPtr> &promise) { promise.set_error(Status::Error(500, "Request aborted")); });
|
||||
|
@ -50,6 +50,8 @@ class SecureManager : public NetQueryCallback {
|
||||
void send_passport_authorization_form(int32 authorization_form_id, std::vector<SecureValueType> types,
|
||||
Promise<> promise);
|
||||
|
||||
void get_preferred_country_code(string country_code, Promise<td_api::object_ptr<td_api::text>> promise);
|
||||
|
||||
private:
|
||||
ActorShared<> parent_;
|
||||
int32 refcnt_{1};
|
||||
|
@ -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_);
|
||||
|
@ -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);
|
||||
|
@ -608,10 +608,9 @@ class CliClient final : public Actor {
|
||||
}
|
||||
|
||||
void on_error(uint64 id, tl_object_ptr<td_api::error> 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<td_api::sendPassportAuthorizationForm>(to_integer<int32>(id),
|
||||
as_passport_element_types(types)));
|
||||
} else if (op == "gpcl") {
|
||||
send_request(make_tl_object<td_api::getPreferredCountryLanguage>(args));
|
||||
} else if (op == "spnvc" || op == "SendPhoneNumberVerificationCode") {
|
||||
send_request(make_tl_object<td_api::sendPhoneNumberVerificationCode>(args, false, false));
|
||||
} else if (op == "cpnvc" || op == "CheckPhoneNumberVerificationCode") {
|
||||
|
Reference in New Issue
Block a user