2018-12-31 20:04:05 +01:00
|
|
|
//
|
2021-01-01 13:57:46 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
|
2018-12-31 20:04:05 +01: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
|
|
|
|
|
2018-06-26 01:43:11 +02:00
|
|
|
#include "td/telegram/net/DcId.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/net/DcOptions.h"
|
|
|
|
#include "td/telegram/net/NetQuery.h"
|
2020-07-11 22:50:21 +02:00
|
|
|
#include "td/telegram/SuggestedAction.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-12-19 02:23:14 +01:00
|
|
|
#include "td/telegram/td_api.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/telegram_api.h"
|
|
|
|
|
|
|
|
#include "td/actor/actor.h"
|
2018-07-03 21:29:04 +02:00
|
|
|
#include "td/actor/PromiseFuture.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-12-23 18:48:30 +01:00
|
|
|
#include "td/utils/common.h"
|
2020-07-16 20:37:13 +02:00
|
|
|
#include "td/utils/FloodControlStrict.h"
|
2018-12-27 20:24:44 +01:00
|
|
|
#include "td/utils/logging.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/Slice.h"
|
|
|
|
#include "td/utils/Status.h"
|
|
|
|
#include "td/utils/Time.h"
|
|
|
|
|
2020-08-14 21:51:10 +02:00
|
|
|
#include <limits>
|
2020-07-12 14:04:49 +02:00
|
|
|
#include <map>
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
namespace td {
|
|
|
|
|
2018-12-26 21:58:18 +01:00
|
|
|
extern int VERBOSITY_NAME(config_recoverer);
|
|
|
|
|
2018-06-30 15:35:37 +02:00
|
|
|
class ConfigShared;
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
using SimpleConfig = tl_object_ptr<telegram_api::help_configSimple>;
|
2019-07-11 13:25:20 +02:00
|
|
|
struct SimpleConfigResult {
|
|
|
|
Result<SimpleConfig> r_config;
|
2019-07-11 22:32:45 +02:00
|
|
|
Result<int32> r_http_date;
|
2019-07-11 13:25:20 +02:00
|
|
|
};
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
Result<SimpleConfig> decode_config(Slice input);
|
|
|
|
|
2019-07-11 13:25:20 +02:00
|
|
|
ActorOwn<> get_simple_config_azure(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config, bool is_test,
|
2018-06-30 15:35:37 +02:00
|
|
|
int32 scheduler_id);
|
2018-03-12 19:04:03 +01:00
|
|
|
|
2019-07-11 13:25:20 +02:00
|
|
|
ActorOwn<> get_simple_config_google_dns(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config,
|
|
|
|
bool is_test, int32 scheduler_id);
|
|
|
|
|
2019-10-03 21:20:15 +02:00
|
|
|
ActorOwn<> get_simple_config_mozilla_dns(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config,
|
|
|
|
bool is_test, int32 scheduler_id);
|
|
|
|
|
2019-11-19 15:58:24 +01:00
|
|
|
ActorOwn<> get_simple_config_firebase_remote_config(Promise<SimpleConfigResult> promise,
|
|
|
|
const ConfigShared *shared_config, bool is_test,
|
|
|
|
int32 scheduler_id);
|
|
|
|
|
2019-11-19 17:01:12 +01:00
|
|
|
ActorOwn<> get_simple_config_firebase_realtime(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config,
|
|
|
|
bool is_test, int32 scheduler_id);
|
|
|
|
|
2019-11-19 17:26:39 +01:00
|
|
|
ActorOwn<> get_simple_config_firebase_firestore(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config,
|
|
|
|
bool is_test, int32 scheduler_id);
|
|
|
|
|
2019-07-11 13:25:20 +02:00
|
|
|
class HttpDate {
|
2019-07-11 22:32:45 +02:00
|
|
|
static bool is_leap(int32 year) {
|
2019-07-11 13:25:20 +02:00
|
|
|
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
|
|
|
|
}
|
2019-07-11 22:32:45 +02:00
|
|
|
static int32 days_in_month(int32 year, int32 month) {
|
2019-07-11 13:25:20 +02:00
|
|
|
static int cnt[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
|
|
|
return cnt[month - 1] + (month == 2 && is_leap(year));
|
|
|
|
}
|
2019-07-11 22:32:45 +02:00
|
|
|
static int32 seconds_in_day() {
|
2019-07-11 13:25:20 +02:00
|
|
|
return 24 * 60 * 60;
|
|
|
|
}
|
2019-07-11 22:32:45 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
static Result<int32> to_unix_time(int32 year, int32 month, int32 day, int32 hour, int32 minute, int32 second);
|
|
|
|
static Result<int32> parse_http_date(std::string slice);
|
2019-07-11 13:25:20 +02:00
|
|
|
};
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
class ConfigRecoverer;
|
2021-07-04 04:58:54 +02:00
|
|
|
class ConfigManager final : public NetQueryCallback {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
|
|
|
explicit ConfigManager(ActorShared<> parent);
|
|
|
|
|
|
|
|
void request_config();
|
|
|
|
|
2020-07-16 20:37:13 +02:00
|
|
|
void lazy_request_config();
|
|
|
|
|
2019-12-19 02:23:14 +01:00
|
|
|
void get_app_config(Promise<td_api::object_ptr<td_api::JsonValue>> &&promise);
|
|
|
|
|
2021-10-06 00:17:10 +02:00
|
|
|
void reget_app_config(Promise<Unit> &&promise);
|
|
|
|
|
2019-12-19 21:00:28 +01:00
|
|
|
void get_content_settings(Promise<Unit> &&promise);
|
|
|
|
|
2019-12-20 00:58:41 +01:00
|
|
|
void set_content_settings(bool ignore_sensitive_content_restrictions, Promise<Unit> &&promise);
|
|
|
|
|
2020-07-10 19:28:30 +02:00
|
|
|
void get_global_privacy_settings(Promise<Unit> &&promise);
|
|
|
|
|
|
|
|
void set_archive_and_mute(bool archive_and_mute, Promise<Unit> &&promise);
|
|
|
|
|
2021-06-11 01:13:46 +02:00
|
|
|
void hide_suggested_action(SuggestedAction suggested_action);
|
|
|
|
|
2020-07-12 14:04:49 +02:00
|
|
|
void dismiss_suggested_action(SuggestedAction suggested_action, Promise<Unit> &&promise);
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void on_dc_options_update(DcOptions dc_options);
|
|
|
|
|
2020-07-11 22:50:21 +02:00
|
|
|
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
private:
|
|
|
|
ActorShared<> parent_;
|
|
|
|
int32 config_sent_cnt_{0};
|
|
|
|
ActorOwn<ConfigRecoverer> config_recoverer_;
|
|
|
|
int ref_cnt_{1};
|
2019-02-10 01:45:15 +01:00
|
|
|
Timestamp expire_time_;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2020-08-23 19:34:05 +02:00
|
|
|
FloodControlStrict lazy_request_flood_control_;
|
2020-07-16 20:37:13 +02:00
|
|
|
|
2019-12-19 02:23:14 +01:00
|
|
|
vector<Promise<td_api::object_ptr<td_api::JsonValue>>> get_app_config_queries_;
|
2021-10-06 00:17:10 +02:00
|
|
|
vector<Promise<Unit>> reget_app_config_queries_;
|
2020-07-10 19:28:30 +02:00
|
|
|
|
2019-12-19 21:00:28 +01:00
|
|
|
vector<Promise<Unit>> get_content_settings_queries_;
|
2019-12-20 00:58:41 +01:00
|
|
|
vector<Promise<Unit>> set_content_settings_queries_[2];
|
|
|
|
bool is_set_content_settings_request_sent_ = false;
|
2019-12-20 02:06:38 +01:00
|
|
|
bool last_set_content_settings_ = false;
|
2019-12-19 02:23:14 +01:00
|
|
|
|
2020-07-10 19:28:30 +02:00
|
|
|
vector<Promise<Unit>> get_global_privacy_settings_queries_;
|
|
|
|
vector<Promise<Unit>> set_archive_and_mute_queries_[2];
|
|
|
|
bool is_set_archive_and_mute_request_sent_ = false;
|
|
|
|
bool last_set_archive_and_mute_ = false;
|
|
|
|
|
2020-07-11 22:50:21 +02:00
|
|
|
vector<SuggestedAction> suggested_actions_;
|
2020-07-12 14:04:49 +02:00
|
|
|
size_t dismiss_suggested_action_request_count_ = 0;
|
2021-02-20 23:06:45 +01:00
|
|
|
std::map<int32, vector<Promise<Unit>>> dismiss_suggested_action_queries_;
|
2020-07-11 22:50:21 +02:00
|
|
|
|
2020-08-11 15:31:50 +02:00
|
|
|
static constexpr uint64 REFCNT_TOKEN = std::numeric_limits<uint64>::max() - 2;
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void start_up() final;
|
|
|
|
void hangup_shared() final;
|
|
|
|
void hangup() final;
|
|
|
|
void loop() final;
|
2018-12-31 20:04:05 +01:00
|
|
|
void try_stop();
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void on_result(NetQueryPtr res) final;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
void request_config_from_dc_impl(DcId dc_id);
|
|
|
|
void process_config(tl_object_ptr<telegram_api::config> config);
|
2020-07-10 19:28:30 +02:00
|
|
|
|
2021-10-06 00:17:10 +02:00
|
|
|
void try_request_app_config();
|
|
|
|
|
2019-12-19 02:58:03 +01:00
|
|
|
void process_app_config(tl_object_ptr<telegram_api::JSONValue> &config);
|
2020-07-10 19:28:30 +02:00
|
|
|
|
|
|
|
void do_set_ignore_sensitive_content_restrictions(bool ignore_sensitive_content_restrictions);
|
|
|
|
|
|
|
|
void do_set_archive_and_mute(bool archive_and_mute);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2020-07-26 14:41:32 +02:00
|
|
|
static Timestamp load_config_expire_time();
|
|
|
|
static void save_config_expire(Timestamp timestamp);
|
2021-10-19 17:11:16 +02:00
|
|
|
static void save_dc_options_update(const DcOptions &dc_options);
|
2020-07-26 14:41:32 +02:00
|
|
|
static DcOptions load_dc_options_update();
|
2020-08-11 15:31:50 +02:00
|
|
|
|
|
|
|
ActorShared<> create_reference();
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
2018-10-28 18:30:47 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace td
|