tdlight/td/telegram/CountryInfoManager.h

95 lines
3.1 KiB
C
Raw Normal View History

//
2022-12-31 22:28:08 +01:00
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
//
// 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/utils/common.h"
2022-02-07 22:04:34 +01:00
#include "td/utils/FlatHashMap.h"
2022-06-27 12:30:18 +02:00
#include "td/utils/Promise.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>
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);
2022-12-20 13:01:39 +01:00
void on_update_fragment_prefixes();
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();
2022-12-20 13:01:39 +01:00
static bool is_fragment_phone_number(string phone_number);
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 FlatHashMap<string, unique_ptr<CountryList>> countries_;
2021-08-30 18:20:40 +02:00
2022-12-20 13:01:39 +01:00
static string fragment_prefixes_str_;
static vector<string> fragment_prefixes_;
FlatHashMap<string, vector<Promise<Unit>>> pending_load_country_queries_;
Td *td_;
ActorShared<> parent_;
};
} // namespace td