tdlight/td/telegram/CountryInfoManager.h

88 lines
2.9 KiB
C
Raw Normal View History

//
2021-01-01 13:57:46 +01:00
// 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"
2021-09-01 19:31:39 +02:00
#include "td/utils/Slice.h"
#include "td/utils/Status.h"
2021-08-30 18:20:40 +02:00
#include <mutex>
#include <unordered_map>
namespace td {
class Td;
class CountryInfoManager final : public Actor {
public:
CountryInfoManager(Td *td, ActorShared<> parent);
void get_countries(Promise<td_api::object_ptr<td_api::countries>> &&promise);
void get_current_country_code(Promise<string> &&promise);
void get_phone_number_info(string phone_number_prefix,
Promise<td_api::object_ptr<td_api::phoneNumberInfo>> &&promise);
2021-10-19 17:11:16 +02:00
static td_api::object_ptr<td_api::phoneNumberInfo> get_phone_number_info_sync(const string &language_code,
2021-08-30 21:26:02 +02:00
string phone_number_prefix);
CountryInfoManager(const CountryInfoManager &) = delete;
CountryInfoManager &operator=(const CountryInfoManager &) = delete;
CountryInfoManager(CountryInfoManager &&) = delete;
CountryInfoManager &operator=(CountryInfoManager &&) = delete;
2021-07-03 22:51:36 +02:00
~CountryInfoManager() final;
private:
2021-08-30 18:20:40 +02:00
void start_up() final;
2021-07-03 22:51:36 +02:00
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<td_api::object_ptr<td_api::countries>> &&promise);
void do_get_phone_number_info(string phone_number_prefix, string language_code, bool is_recursive,
Promise<td_api::object_ptr<td_api::phoneNumberInfo>> &&promise);
void load_country_list(string language_code, int32 hash, Promise<Unit> &&promise);
void on_get_country_list(const string &language_code,
Result<tl_object_ptr<telegram_api::help_CountriesList>> r_country_list);
2021-08-30 18:20:40 +02:00
static void on_get_country_list_impl(const string &language_code,
tl_object_ptr<telegram_api::help_CountriesList> country_list);
2021-08-30 18:20:40 +02:00
static const CountryList *get_country_list(CountryInfoManager *manager, const string &language_code);
static td_api::object_ptr<td_api::phoneNumberInfo> get_phone_number_info_object(const CountryList *list,
Slice phone_number);
2021-08-30 18:20:40 +02:00
static std::mutex country_mutex_;
static int32 manager_count_;
static std::unordered_map<string, unique_ptr<CountryList>> countries_;
std::unordered_map<string, vector<Promise<Unit>>> pending_load_country_queries_;
Td *td_;
ActorShared<> parent_;
};
} // namespace td