Skip to content

Commit

Permalink
Add td_api::getPhoneNumberInfoSync.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Aug 30, 2021
1 parent a684027 commit 086ec3d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions td/generate/scheme/td_api.tl
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 16 additions & 0 deletions td/telegram/CountryInfoManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions td/telegram/CountryInfoManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions td/telegram/Td.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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_);
Expand Down
3 changes: 3 additions & 0 deletions td/telegram/Td.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions td/telegram/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit 086ec3d

Please sign in to comment.