2020-08-23 23:43:31 +02:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
2020-08-23 23:43:31 +02:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
2020-08-24 22:38:45 +02:00
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
#include "td/telegram/telegram_api.h"
|
|
|
|
|
2020-08-24 13:39:03 +02:00
|
|
|
#include "td/actor/actor.h"
|
2020-08-23 23:43:31 +02:00
|
|
|
|
|
|
|
#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"
|
2020-08-24 22:38:45 +02:00
|
|
|
#include "td/utils/Status.h"
|
|
|
|
|
2021-08-30 18:20:40 +02:00
|
|
|
#include <mutex>
|
2020-08-23 23:43:31 +02:00
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
class Td;
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class CountryInfoManager final : public Actor {
|
2020-08-23 23:43:31 +02:00
|
|
|
public:
|
2020-09-24 18:15:42 +02:00
|
|
|
CountryInfoManager(Td *td, ActorShared<> parent);
|
2020-08-23 23:43:31 +02:00
|
|
|
|
2020-08-24 22:38:45 +02:00
|
|
|
void get_countries(Promise<td_api::object_ptr<td_api::countries>> &&promise);
|
|
|
|
|
2020-08-23 23:43:31 +02:00
|
|
|
void get_current_country_code(Promise<string> &&promise);
|
|
|
|
|
2020-08-25 12:42:14 +02:00
|
|
|
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);
|
|
|
|
|
2024-01-05 11:42:46 +01:00
|
|
|
static string get_country_flag_emoji(const string &country_code);
|
|
|
|
|
2022-12-20 13:01:39 +01:00
|
|
|
void on_update_fragment_prefixes();
|
|
|
|
|
2020-09-14 17:02:19 +02:00
|
|
|
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;
|
2020-09-14 17:02:19 +02:00
|
|
|
|
2020-08-23 23:43:31 +02:00
|
|
|
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;
|
2020-08-24 13:39:03 +02:00
|
|
|
|
2020-08-24 22:38:45 +02:00
|
|
|
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);
|
|
|
|
|
2020-08-24 22:38:45 +02:00
|
|
|
void do_get_countries(string language_code, bool is_recursive,
|
|
|
|
Promise<td_api::object_ptr<td_api::countries>> &&promise);
|
|
|
|
|
2020-08-25 12:42:14 +02:00
|
|
|
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);
|
|
|
|
|
2020-08-24 22:38:45 +02:00
|
|
|
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);
|
2020-09-25 14:14:33 +02:00
|
|
|
|
2021-08-30 18:20:40 +02:00
|
|
|
static const CountryList *get_country_list(CountryInfoManager *manager, const string &language_code);
|
2020-08-24 22:38:45 +02:00
|
|
|
|
2021-08-30 16:51:09 +02:00
|
|
|
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_;
|
|
|
|
|
2022-02-07 20:41:07 +01:00
|
|
|
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_;
|
|
|
|
|
2022-02-07 20:41:07 +01:00
|
|
|
FlatHashMap<string, vector<Promise<Unit>>> pending_load_country_queries_;
|
2020-08-24 22:38:45 +02:00
|
|
|
|
2020-08-23 23:43:31 +02:00
|
|
|
Td *td_;
|
2020-08-24 13:39:03 +02:00
|
|
|
ActorShared<> parent_;
|
2020-08-23 23:43:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|