// // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #pragma once #include "td/telegram/td_api.h" #include "td/telegram/telegram_api.h" #include "td/actor/actor.h" #include "td/actor/PromiseFuture.h" #include "td/utils/common.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" #include #include namespace td { class Td; class CountryInfoManager final : public Actor { public: CountryInfoManager(Td *td, ActorShared<> parent); void get_countries(Promise> &&promise); void get_current_country_code(Promise &&promise); void get_phone_number_info(string phone_number_prefix, Promise> &&promise); static td_api::object_ptr get_phone_number_info_sync(const string &language_code, string phone_number_prefix); CountryInfoManager(const CountryInfoManager &) = delete; CountryInfoManager &operator=(const CountryInfoManager &) = delete; CountryInfoManager(CountryInfoManager &&) = delete; CountryInfoManager &operator=(CountryInfoManager &&) = delete; ~CountryInfoManager() final; private: void start_up() final; void tear_down() final; struct CallingCodeInfo; struct CountryInfo; struct CountryList; string get_main_language_code(); void do_get_countries(string language_code, bool is_recursive, Promise> &&promise); void do_get_phone_number_info(string phone_number_prefix, string language_code, bool is_recursive, Promise> &&promise); void load_country_list(string language_code, int32 hash, Promise &&promise); void on_get_country_list(const string &language_code, Result> r_country_list); static void on_get_country_list_impl(const string &language_code, tl_object_ptr country_list); static const CountryList *get_country_list(CountryInfoManager *manager, const string &language_code); static td_api::object_ptr get_phone_number_info_object(const CountryList *list, Slice phone_number); static std::mutex country_mutex_; static int32 manager_count_; static std::unordered_map> countries_; std::unordered_map>> pending_load_country_queries_; Td *td_; ActorShared<> parent_; }; } // namespace td