Add td_api::getPhoneNumberInfoSync.

This commit is contained in:
levlam 2021-08-30 22:26:02 +03:00
parent a68402719c
commit 086ec3d2e5
6 changed files with 38 additions and 0 deletions

View File

@ -5446,6 +5446,10 @@ getCountryCode = Text;
//@description Returns information about a phone number by its prefix. Can be called before authorization @phone_number_prefix The phone number prefix
getPhoneNumberInfo phone_number_prefix:string = PhoneNumberInfo;
//@description Returns information about a phone number by its prefix synchronously. getCountries must be called at least once after changing localization to the specified language if properly localized country information is expected. Can be called synchronously
//@language_code A two-letter ISO 639-1 country code for country information localization @phone_number_prefix The phone number prefix
getPhoneNumberInfoSync language_code:string phone_number_prefix:string = PhoneNumberInfo;
//@description Returns the link for downloading official Telegram application to be used when the current user invites friends to Telegram
getApplicationDownloadLink = HttpUrl;

View File

@ -216,6 +216,22 @@ void CountryInfoManager::do_get_phone_number_info(string phone_number_prefix, st
}));
}
td_api::object_ptr<td_api::phoneNumberInfo> CountryInfoManager::get_phone_number_info_sync(string language_code,
string phone_number_prefix) {
td::remove_if(phone_number_prefix, [](char c) { return c < '0' || c > '9'; });
if (phone_number_prefix.empty()) {
return td_api::make_object<td_api::phoneNumberInfo>(nullptr, string(), string());
}
std::lock_guard<std::mutex> country_lock(country_mutex_);
auto list = get_country_list(nullptr, language_code);
if (list == nullptr) {
list = get_country_list(nullptr, "en");
}
return get_phone_number_info_object(list, phone_number_prefix);
}
td_api::object_ptr<td_api::phoneNumberInfo> CountryInfoManager::get_phone_number_info_object(const CountryList *list,
Slice phone_number) {
CHECK(list != nullptr);

View File

@ -33,6 +33,9 @@ class CountryInfoManager final : public Actor {
void get_phone_number_info(string phone_number_prefix,
Promise<td_api::object_ptr<td_api::phoneNumberInfo>> &&promise);
static td_api::object_ptr<td_api::phoneNumberInfo> get_phone_number_info_sync(string language_code,
string phone_number_prefix);
CountryInfoManager(const CountryInfoManager &) = delete;
CountryInfoManager &operator=(const CountryInfoManager &) = delete;
CountryInfoManager(CountryInfoManager &&) = delete;

View File

@ -3152,6 +3152,7 @@ bool Td::is_synchronous_request(int32 id) {
case td_api::getFileExtension::ID:
case td_api::cleanFileName::ID:
case td_api::getLanguagePackString::ID:
case td_api::getPhoneNumberInfoSync::ID:
case td_api::getChatFilterDefaultIconName::ID:
case td_api::getJsonValue::ID:
case td_api::getJsonString::ID:
@ -8269,6 +8270,10 @@ void Td::on_request(uint64 id, const td_api::getLanguagePackString &request) {
UNREACHABLE();
}
void Td::on_request(uint64 id, const td_api::getPhoneNumberInfoSync &request) {
UNREACHABLE();
}
void Td::on_request(uint64 id, const td_api::getPushReceiverId &request) {
UNREACHABLE();
}
@ -8420,6 +8425,11 @@ td_api::object_ptr<td_api::Object> Td::do_static_request(const td_api::getLangua
request.language_pack_database_path_, request.localization_target_, request.language_pack_id_, request.key_);
}
td_api::object_ptr<td_api::Object> Td::do_static_request(const td_api::getPhoneNumberInfoSync &request) {
// don't check language_code/phone number UTF-8 correctness
return CountryInfoManager::get_phone_number_info_sync(request.language_code_, request.phone_number_prefix_);
}
td_api::object_ptr<td_api::Object> Td::do_static_request(const td_api::getPushReceiverId &request) {
// don't check push payload UTF-8 correctness
auto r_push_receiver_id = NotificationManager::get_push_receiver_id(request.payload_);

View File

@ -1224,6 +1224,8 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, const td_api::getLanguagePackString &request);
void on_request(uint64 id, const td_api::getPhoneNumberInfoSync &request);
void on_request(uint64 id, const td_api::getPushReceiverId &request);
void on_request(uint64 id, const td_api::getChatFilterDefaultIconName &request);
@ -1275,6 +1277,7 @@ class Td final : public NetQueryCallback {
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getFileExtension &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::cleanFileName &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getLanguagePackString &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getPhoneNumberInfoSync &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getPushReceiverId &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getChatFilterDefaultIconName &request);
static td_api::object_ptr<td_api::Object> do_static_request(td_api::getJsonValue &request);

View File

@ -2310,6 +2310,8 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::getCountryCode>());
} else if (op == "gpni") {
send_request(td_api::make_object<td_api::getPhoneNumberInfo>(args));
} else if (op == "gpnis") {
execute(td_api::make_object<td_api::getPhoneNumberInfoSync>(rand_bool() ? "en" : "", args));
} else if (op == "gadl") {
send_request(td_api::make_object<td_api::getApplicationDownloadLink>());
} else if (op == "atos") {