Proxy all option-related requests through G.

This commit is contained in:
levlam 2022-08-17 16:11:13 +03:00
parent e49135e542
commit 3318ffdb20
36 changed files with 334 additions and 343 deletions

View File

@ -7,7 +7,6 @@
#include "td/telegram/AnimationsManager.h" #include "td/telegram/AnimationsManager.h"
#include "td/telegram/AuthManager.h" #include "td/telegram/AuthManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/DialogId.h" #include "td/telegram/DialogId.h"
#include "td/telegram/Document.h" #include "td/telegram/Document.h"
#include "td/telegram/DocumentsManager.h" #include "td/telegram/DocumentsManager.h"
@ -412,7 +411,7 @@ void AnimationsManager::on_update_animation_search_emojis(string animation_searc
return; return;
} }
if (td_->auth_manager_->is_bot()) { if (td_->auth_manager_->is_bot()) {
G()->shared_config().set_option_empty("animation_search_emojis"); G()->set_option_empty("animation_search_emojis");
return; return;
} }
@ -430,7 +429,7 @@ void AnimationsManager::on_update_animation_search_provider(string animation_sea
return; return;
} }
if (td_->auth_manager_->is_bot()) { if (td_->auth_manager_->is_bot()) {
G()->shared_config().set_option_empty("animation_search_provider"); G()->set_option_empty("animation_search_provider");
return; return;
} }

View File

@ -9,7 +9,6 @@
#include "td/telegram/AttachMenuManager.h" #include "td/telegram/AttachMenuManager.h"
#include "td/telegram/AuthManager.hpp" #include "td/telegram/AuthManager.hpp"
#include "td/telegram/ConfigManager.h" #include "td/telegram/ConfigManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ContactsManager.h" #include "td/telegram/ContactsManager.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
#include "td/telegram/logevent/LogEvent.h" #include "td/telegram/logevent/LogEvent.h"
@ -51,7 +50,7 @@ AuthManager::AuthManager(int32 api_id, const string &api_hash, ActorShared<> par
if (my_id.is_valid()) { if (my_id.is_valid()) {
// just in case // just in case
LOG(INFO) << "Logged in as " << my_id; LOG(INFO) << "Logged in as " << my_id;
G()->shared_config().set_option_integer("my_id", my_id.get()); G()->set_option_integer("my_id", my_id.get());
update_state(State::Ok); update_state(State::Ok);
} else { } else {
LOG(ERROR) << "Restore unknown my_id"; LOG(ERROR) << "Restore unknown my_id";
@ -701,8 +700,7 @@ void AuthManager::on_log_out_result(NetQueryPtr &result) {
if (r_log_out.is_ok()) { if (r_log_out.is_ok()) {
auto logged_out = r_log_out.move_as_ok(); auto logged_out = r_log_out.move_as_ok();
if (!logged_out->future_auth_token_.empty()) { if (!logged_out->future_auth_token_.empty()) {
G()->shared_config().set_option_string("authentication_token", G()->set_option_string("authentication_token", base64url_encode(logged_out->future_auth_token_.as_slice()));
base64url_encode(logged_out->future_auth_token_.as_slice()));
} }
} else { } else {
status = r_log_out.move_as_error(); status = r_log_out.move_as_error();
@ -792,7 +790,7 @@ void AuthManager::on_get_authorization(tl_object_ptr<telegram_api::auth_Authoriz
} }
auto auth = telegram_api::move_object_as<telegram_api::auth_authorization>(auth_ptr); auto auth = telegram_api::move_object_as<telegram_api::auth_authorization>(auth_ptr);
G()->shared_config().set_option_integer("authorization_date", G()->unix_time()); G()->set_option_integer("authorization_date", G()->unix_time());
if (was_check_bot_token_) { if (was_check_bot_token_) {
is_bot_ = true; is_bot_ = true;
G()->td_db()->get_binlog_pmc()->set("auth_is_bot", "true"); G()->td_db()->get_binlog_pmc()->set("auth_is_bot", "true");
@ -815,10 +813,10 @@ void AuthManager::on_get_authorization(tl_object_ptr<telegram_api::auth_Authoriz
return; return;
} }
if ((auth->flags_ & telegram_api::auth_authorization::TMP_SESSIONS_MASK) != 0) { if ((auth->flags_ & telegram_api::auth_authorization::TMP_SESSIONS_MASK) != 0) {
G()->shared_config().set_option_integer("session_count", auth->tmp_sessions_); G()->set_option_integer("session_count", auth->tmp_sessions_);
} }
if (auth->setup_password_required_ && auth->otherwise_relogin_days_ > 0) { if (auth->setup_password_required_ && auth->otherwise_relogin_days_ > 0) {
G()->shared_config().set_option_integer("otherwise_relogin_days", auth->otherwise_relogin_days_); G()->set_option_integer("otherwise_relogin_days", auth->otherwise_relogin_days_);
} }
td_->attach_menu_manager_->init(); td_->attach_menu_manager_->init();
td_->messages_manager_->on_authorization_success(); td_->messages_manager_->on_authorization_success();

View File

@ -8,7 +8,6 @@
#include "td/telegram/AuthManager.h" #include "td/telegram/AuthManager.h"
#include "td/telegram/BackgroundType.hpp" #include "td/telegram/BackgroundType.hpp"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/DialogId.h" #include "td/telegram/DialogId.h"
#include "td/telegram/Document.h" #include "td/telegram/Document.h"
#include "td/telegram/DocumentsManager.h" #include "td/telegram/DocumentsManager.h"
@ -453,7 +452,7 @@ void BackgroundManager::get_backgrounds(bool for_dark_theme,
Result<string> BackgroundManager::get_background_url(const string &name, Result<string> BackgroundManager::get_background_url(const string &name,
td_api::object_ptr<td_api::BackgroundType> background_type) { td_api::object_ptr<td_api::BackgroundType> background_type) {
TRY_RESULT(type, BackgroundType::get_background_type(background_type.get())); TRY_RESULT(type, BackgroundType::get_background_type(background_type.get()));
auto url = PSTRING() << G()->shared_config().get_option_string("t_me_url", "https://t.me/") << "bg/"; auto url = PSTRING() << G()->get_option_string("t_me_url", "https://t.me/") << "bg/";
auto link = type.get_link(); auto link = type.get_link();
if (type.has_file()) { if (type.has_file()) {
url += name; url += name;

View File

@ -6,7 +6,6 @@
// //
#include "td/telegram/CallActor.h" #include "td/telegram/CallActor.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ContactsManager.h" #include "td/telegram/ContactsManager.h"
#include "td/telegram/DhCache.h" #include "td/telegram/DhCache.h"
#include "td/telegram/DialogId.h" #include "td/telegram/DialogId.h"
@ -511,7 +510,7 @@ Status CallActor::do_update_call(telegram_api::phoneCallWaiting &call) {
if ((call.flags_ & telegram_api::phoneCallWaiting::RECEIVE_DATE_MASK) != 0) { if ((call.flags_ & telegram_api::phoneCallWaiting::RECEIVE_DATE_MASK) != 0) {
call_state_.is_received = true; call_state_.is_received = true;
call_state_need_flush_ = true; call_state_need_flush_ = true;
int64 call_ring_timeout_ms = G()->shared_config().get_option_integer("call_ring_timeout_ms", 90000); int64 call_ring_timeout_ms = G()->get_option_integer("call_ring_timeout_ms", 90000);
set_timeout_in(static_cast<double>(call_ring_timeout_ms) * 0.001); set_timeout_in(static_cast<double>(call_ring_timeout_ms) * 0.001);
} }
} }
@ -594,7 +593,7 @@ Status CallActor::do_update_call(telegram_api::phoneCallAccepted &call) {
void CallActor::on_begin_exchanging_key() { void CallActor::on_begin_exchanging_key() {
call_state_.type = CallState::Type::ExchangingKey; call_state_.type = CallState::Type::ExchangingKey;
call_state_need_flush_ = true; call_state_need_flush_ = true;
int64 call_receive_timeout_ms = G()->shared_config().get_option_integer("call_receive_timeout_ms", 20000); int64 call_receive_timeout_ms = G()->get_option_integer("call_receive_timeout_ms", 20000);
auto timeout = static_cast<double>(call_receive_timeout_ms) * 0.001; auto timeout = static_cast<double>(call_receive_timeout_ms) * 0.001;
LOG(INFO) << "Set call timeout to " << timeout; LOG(INFO) << "Set call timeout to " << timeout;
set_timeout_in(timeout); set_timeout_in(timeout);
@ -773,7 +772,7 @@ void CallActor::try_send_request_query() {
call_state_.protocol.get_input_phone_call_protocol()); call_state_.protocol.get_input_phone_call_protocol());
auto query = G()->net_query_creator().create(tl_query); auto query = G()->net_query_creator().create(tl_query);
state_ = State::WaitRequestResult; state_ = State::WaitRequestResult;
int64 call_receive_timeout_ms = G()->shared_config().get_option_integer("call_receive_timeout_ms", 20000); int64 call_receive_timeout_ms = G()->get_option_integer("call_receive_timeout_ms", 20000);
auto timeout = static_cast<double>(call_receive_timeout_ms) * 0.001; auto timeout = static_cast<double>(call_receive_timeout_ms) * 0.001;
LOG(INFO) << "Set call timeout to " << timeout; LOG(INFO) << "Set call timeout to " << timeout;
set_timeout_in(timeout); set_timeout_in(timeout);

View File

@ -7,7 +7,6 @@
#include "td/telegram/ConfigManager.h" #include "td/telegram/ConfigManager.h"
#include "td/telegram/AuthManager.h" #include "td/telegram/AuthManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ConnectionState.h" #include "td/telegram/ConnectionState.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
#include "td/telegram/JsonValue.h" #include "td/telegram/JsonValue.h"
@ -244,7 +243,7 @@ static ActorOwn<> get_simple_config_impl(Promise<SimpleConfigResult> promise, in
#endif #endif
} }
ActorOwn<> get_simple_config_azure(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config, bool is_test, ActorOwn<> get_simple_config_azure(Promise<SimpleConfigResult> promise, const Global *shared_config, bool is_test,
int32 scheduler_id) { int32 scheduler_id) {
string url = PSTRING() << "https://software-download.microsoft.com/" << (is_test ? "test" : "prod") string url = PSTRING() << "https://software-download.microsoft.com/" << (is_test ? "test" : "prod")
<< "v2/config.txt"; << "v2/config.txt";
@ -255,7 +254,7 @@ ActorOwn<> get_simple_config_azure(Promise<SimpleConfigResult> promise, const Co
} }
static ActorOwn<> get_simple_config_dns(Slice address, Slice host, Promise<SimpleConfigResult> promise, static ActorOwn<> get_simple_config_dns(Slice address, Slice host, Promise<SimpleConfigResult> promise,
const ConfigShared *shared_config, bool is_test, int32 scheduler_id) { const Global *shared_config, bool is_test, int32 scheduler_id) {
string name = shared_config == nullptr ? string() : shared_config->get_option_string("dc_txt_domain_name"); string name = shared_config == nullptr ? string() : shared_config->get_option_string("dc_txt_domain_name");
const bool prefer_ipv6 = shared_config == nullptr ? false : shared_config->get_option_boolean("prefer_ipv6"); const bool prefer_ipv6 = shared_config == nullptr ? false : shared_config->get_option_boolean("prefer_ipv6");
if (name.empty()) { if (name.empty()) {
@ -307,14 +306,14 @@ static ActorOwn<> get_simple_config_dns(Slice address, Slice host, Promise<Simpl
host.str(), {{"Accept", "application/dns-json"}}, prefer_ipv6, std::move(get_config)); host.str(), {{"Accept", "application/dns-json"}}, prefer_ipv6, std::move(get_config));
} }
ActorOwn<> get_simple_config_google_dns(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config, ActorOwn<> get_simple_config_google_dns(Promise<SimpleConfigResult> promise, const Global *shared_config, bool is_test,
bool is_test, int32 scheduler_id) { int32 scheduler_id) {
return get_simple_config_dns("dns.google/resolve", "dns.google", std::move(promise), shared_config, is_test, return get_simple_config_dns("dns.google/resolve", "dns.google", std::move(promise), shared_config, is_test,
scheduler_id); scheduler_id);
} }
ActorOwn<> get_simple_config_mozilla_dns(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config, ActorOwn<> get_simple_config_mozilla_dns(Promise<SimpleConfigResult> promise, const Global *shared_config, bool is_test,
bool is_test, int32 scheduler_id) { int32 scheduler_id) {
return get_simple_config_dns("mozilla.cloudflare-dns.com/dns-query", "mozilla.cloudflare-dns.com", std::move(promise), return get_simple_config_dns("mozilla.cloudflare-dns.com/dns-query", "mozilla.cloudflare-dns.com", std::move(promise),
shared_config, is_test, scheduler_id); shared_config, is_test, scheduler_id);
} }
@ -329,9 +328,8 @@ static string generate_firebase_remote_config_payload() {
<< app_instance_id << "\"}"; << app_instance_id << "\"}";
} }
ActorOwn<> get_simple_config_firebase_remote_config(Promise<SimpleConfigResult> promise, ActorOwn<> get_simple_config_firebase_remote_config(Promise<SimpleConfigResult> promise, const Global *shared_config,
const ConfigShared *shared_config, bool is_test, bool is_test, int32 scheduler_id) {
int32 scheduler_id) {
if (is_test) { if (is_test) {
promise.set_error(Status::Error(400, "Test config is not supported")); promise.set_error(Status::Error(400, "Test config is not supported"));
return ActorOwn<>(); return ActorOwn<>();
@ -355,7 +353,7 @@ ActorOwn<> get_simple_config_firebase_remote_config(Promise<SimpleConfigResult>
{}, prefer_ipv6, std::move(get_config), payload, "application/json"); {}, prefer_ipv6, std::move(get_config), payload, "application/json");
} }
ActorOwn<> get_simple_config_firebase_realtime(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config, ActorOwn<> get_simple_config_firebase_realtime(Promise<SimpleConfigResult> promise, const Global *shared_config,
bool is_test, int32 scheduler_id) { bool is_test, int32 scheduler_id) {
if (is_test) { if (is_test) {
promise.set_error(Status::Error(400, "Test config is not supported")); promise.set_error(Status::Error(400, "Test config is not supported"));
@ -371,7 +369,7 @@ ActorOwn<> get_simple_config_firebase_realtime(Promise<SimpleConfigResult> promi
prefer_ipv6, std::move(get_config)); prefer_ipv6, std::move(get_config));
} }
ActorOwn<> get_simple_config_firebase_firestore(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config, ActorOwn<> get_simple_config_firebase_firestore(Promise<SimpleConfigResult> promise, const Global *shared_config,
bool is_test, int32 scheduler_id) { bool is_test, int32 scheduler_id) {
if (is_test) { if (is_test) {
promise.set_error(Status::Error(400, "Test config is not supported")); promise.set_error(Status::Error(400, "Test config is not supported"));
@ -661,7 +659,7 @@ class ConfigRecoverer final : public Actor {
auto config = r_simple_config.move_as_ok(); auto config = r_simple_config.move_as_ok();
VLOG(config_recoverer) << "Receive raw " << to_string(config); VLOG(config_recoverer) << "Receive raw " << to_string(config);
if (config->expires_ >= G()->unix_time()) { if (config->expires_ >= G()->unix_time()) {
string phone_number = G()->shared_config().get_option_string("my_phone_number"); string phone_number = G()->get_option_string("my_phone_number");
simple_config_.dc_options.clear(); simple_config_.dc_options.clear();
for (auto &rule : config->rules_) { for (auto &rule : config->rules_) {
@ -708,7 +706,7 @@ class ConfigRecoverer final : public Actor {
} }
static bool expect_blocking() { static bool expect_blocking() {
return G()->shared_config().get_option_boolean("expect_blocking", true); return G()->get_option_boolean("expect_blocking", true);
} }
double get_config_expire_time() const { double get_config_expire_time() const {
@ -842,8 +840,7 @@ class ConfigRecoverer final : public Actor {
return get_simple_config_mozilla_dns; return get_simple_config_mozilla_dns;
} }
}(); }();
simple_config_query_ = simple_config_query_ = get_simple_config(std::move(promise), G(), G()->is_test_dc(), G()->get_gc_scheduler_id());
get_simple_config(std::move(promise), &G()->shared_config(), G()->is_test_dc(), G()->get_gc_scheduler_id());
simple_config_turn_++; simple_config_turn_++;
} }
@ -1101,9 +1098,8 @@ void ConfigManager::request_config_from_dc_impl(DcId dc_id, bool reopen_sessions
} }
void ConfigManager::do_set_ignore_sensitive_content_restrictions(bool ignore_sensitive_content_restrictions) { void ConfigManager::do_set_ignore_sensitive_content_restrictions(bool ignore_sensitive_content_restrictions) {
G()->shared_config().set_option_boolean("ignore_sensitive_content_restrictions", G()->set_option_boolean("ignore_sensitive_content_restrictions", ignore_sensitive_content_restrictions);
ignore_sensitive_content_restrictions); bool have_ignored_restriction_reasons = G()->have_option("ignored_restriction_reasons");
bool have_ignored_restriction_reasons = G()->shared_config().have_option("ignored_restriction_reasons");
if (have_ignored_restriction_reasons != ignore_sensitive_content_restrictions) { if (have_ignored_restriction_reasons != ignore_sensitive_content_restrictions) {
reget_app_config(Auto()); reget_app_config(Auto());
} }
@ -1113,7 +1109,7 @@ void ConfigManager::do_set_archive_and_mute(bool archive_and_mute) {
if (archive_and_mute) { if (archive_and_mute) {
remove_suggested_action(suggested_actions_, SuggestedAction{SuggestedAction::Type::EnableArchiveAndMuteNewChats}); remove_suggested_action(suggested_actions_, SuggestedAction{SuggestedAction::Type::EnableArchiveAndMuteNewChats});
} }
G()->shared_config().set_option_boolean("archive_and_mute_new_chats_from_unknown_users", archive_and_mute); G()->set_option_boolean("archive_and_mute_new_chats_from_unknown_users", archive_and_mute);
} }
void ConfigManager::hide_suggested_action(SuggestedAction suggested_action) { void ConfigManager::hide_suggested_action(SuggestedAction suggested_action) {
@ -1211,7 +1207,7 @@ void ConfigManager::on_result(NetQueryPtr res) {
if (result_ptr.is_error()) { if (result_ptr.is_error()) {
fail_promises(set_content_settings_queries_[ignore_sensitive_content_restrictions], result_ptr.move_as_error()); fail_promises(set_content_settings_queries_[ignore_sensitive_content_restrictions], result_ptr.move_as_error());
} else { } else {
if (G()->shared_config().get_option_boolean("can_ignore_sensitive_content_restrictions") && if (G()->get_option_boolean("can_ignore_sensitive_content_restrictions") &&
last_set_content_settings_ == ignore_sensitive_content_restrictions) { last_set_content_settings_ == ignore_sensitive_content_restrictions) {
do_set_ignore_sensitive_content_restrictions(ignore_sensitive_content_restrictions); do_set_ignore_sensitive_content_restrictions(ignore_sensitive_content_restrictions);
} }
@ -1237,7 +1233,7 @@ void ConfigManager::on_result(NetQueryPtr res) {
auto result = result_ptr.move_as_ok(); auto result = result_ptr.move_as_ok();
do_set_ignore_sensitive_content_restrictions(result->sensitive_enabled_); do_set_ignore_sensitive_content_restrictions(result->sensitive_enabled_);
G()->shared_config().set_option_boolean("can_ignore_sensitive_content_restrictions", result->sensitive_can_change_); G()->set_option_boolean("can_ignore_sensitive_content_restrictions", result->sensitive_can_change_);
set_promises(get_content_settings_queries_); set_promises(get_content_settings_queries_);
return; return;
@ -1328,7 +1324,7 @@ void ConfigManager::process_config(tl_object_ptr<telegram_api::config> config) {
set_timeout_at(expire_time_.at()); set_timeout_at(expire_time_.at());
LOG_IF(ERROR, config->test_mode_ != G()->is_test_dc()) << "Wrong parameter is_test"; LOG_IF(ERROR, config->test_mode_ != G()->is_test_dc()) << "Wrong parameter is_test";
ConfigShared &shared_config = G()->shared_config(); Global &shared_config = *G();
// Do not save dc_options in config, because it will be interpreted and saved by ConnectionCreator. // Do not save dc_options in config, because it will be interpreted and saved by ConnectionCreator.
send_closure(G()->connection_creator(), &ConnectionCreator::on_dc_options, DcOptions(config->dc_options_)); send_closure(G()->connection_creator(), &ConnectionCreator::on_dc_options, DcOptions(config->dc_options_));
@ -1461,8 +1457,7 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
CHECK(config != nullptr); CHECK(config != nullptr);
LOG(INFO) << "Receive app config " << to_string(config); LOG(INFO) << "Receive app config " << to_string(config);
const bool archive_and_mute = const bool archive_and_mute = G()->get_option_boolean("archive_and_mute_new_chats_from_unknown_users");
G()->shared_config().get_option_boolean("archive_and_mute_new_chats_from_unknown_users");
string autologin_token; string autologin_token;
vector<string> autologin_domains; vector<string> autologin_domains;
@ -1701,16 +1696,16 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
auto setting_value = get_json_value_int(std::move(video_note_setting->value_), Slice()); auto setting_value = get_json_value_int(std::move(video_note_setting->value_), Slice());
if (setting_value > 0) { if (setting_value > 0) {
if (video_note_setting->key_ == "diameter") { if (video_note_setting->key_ == "diameter") {
G()->shared_config().set_option_integer("suggested_video_note_length", setting_value); G()->set_option_integer("suggested_video_note_length", setting_value);
} }
if (video_note_setting->key_ == "video_bitrate") { if (video_note_setting->key_ == "video_bitrate") {
G()->shared_config().set_option_integer("suggested_video_note_video_bitrate", setting_value); G()->set_option_integer("suggested_video_note_video_bitrate", setting_value);
} }
if (video_note_setting->key_ == "audio_bitrate") { if (video_note_setting->key_ == "audio_bitrate") {
G()->shared_config().set_option_integer("suggested_video_note_audio_bitrate", setting_value); G()->set_option_integer("suggested_video_note_audio_bitrate", setting_value);
} }
if (video_note_setting->key_ == "max_size") { if (video_note_setting->key_ == "max_size") {
G()->shared_config().set_option_integer("video_note_size_max", setting_value); G()->set_option_integer("video_note_size_max", setting_value);
} }
} }
} else { } else {
@ -1740,17 +1735,17 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
} }
if (key == "ringtone_duration_max") { if (key == "ringtone_duration_max") {
auto setting_value = get_json_value_int(std::move(key_value->value_), key); auto setting_value = get_json_value_int(std::move(key_value->value_), key);
G()->shared_config().set_option_integer("notification_sound_duration_max", setting_value); G()->set_option_integer("notification_sound_duration_max", setting_value);
continue; continue;
} }
if (key == "ringtone_size_max") { if (key == "ringtone_size_max") {
auto setting_value = get_json_value_int(std::move(key_value->value_), key); auto setting_value = get_json_value_int(std::move(key_value->value_), key);
G()->shared_config().set_option_integer("notification_sound_size_max", setting_value); G()->set_option_integer("notification_sound_size_max", setting_value);
continue; continue;
} }
if (key == "ringtone_saved_count_max") { if (key == "ringtone_saved_count_max") {
auto setting_value = get_json_value_int(std::move(key_value->value_), key); auto setting_value = get_json_value_int(std::move(key_value->value_), key);
G()->shared_config().set_option_integer("notification_sound_count_max", setting_value); G()->set_option_integer("notification_sound_count_max", setting_value);
continue; continue;
} }
if (key == "premium_promo_order") { if (key == "premium_promo_order") {
@ -1774,7 +1769,7 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
if (suffix == "_limit_default" || suffix == "_limit_premium") { if (suffix == "_limit_default" || suffix == "_limit_premium") {
auto setting_value = get_json_value_int(std::move(key_value->value_), key); auto setting_value = get_json_value_int(std::move(key_value->value_), key);
if (setting_value > 0) { if (setting_value > 0) {
G()->shared_config().set_option_integer(key, setting_value); G()->set_option_integer(key, setting_value);
} else { } else {
LOG(ERROR) << "Receive invalid value " << setting_value << " for " << key; LOG(ERROR) << "Receive invalid value " << setting_value << " for " << key;
} }
@ -1817,7 +1812,7 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
send_closure(G()->link_manager(), &LinkManager::update_autologin_domains, std::move(autologin_token), send_closure(G()->link_manager(), &LinkManager::update_autologin_domains, std::move(autologin_token),
std::move(autologin_domains), std::move(url_auth_domains)); std::move(autologin_domains), std::move(url_auth_domains));
ConfigShared &shared_config = G()->shared_config(); Global &shared_config = *G();
if (ignored_restriction_reasons.empty()) { if (ignored_restriction_reasons.empty()) {
shared_config.set_option_empty("ignored_restriction_reasons"); shared_config.set_option_empty("ignored_restriction_reasons");

View File

@ -30,7 +30,7 @@ namespace td {
extern int VERBOSITY_NAME(config_recoverer); extern int VERBOSITY_NAME(config_recoverer);
class ConfigShared; class Global;
using SimpleConfig = tl_object_ptr<telegram_api::help_configSimple>; using SimpleConfig = tl_object_ptr<telegram_api::help_configSimple>;
struct SimpleConfigResult { struct SimpleConfigResult {
@ -40,23 +40,22 @@ struct SimpleConfigResult {
Result<SimpleConfig> decode_config(Slice input); Result<SimpleConfig> decode_config(Slice input);
ActorOwn<> get_simple_config_azure(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config, bool is_test, ActorOwn<> get_simple_config_azure(Promise<SimpleConfigResult> promise, const Global *shared_config, bool is_test,
int32 scheduler_id); int32 scheduler_id);
ActorOwn<> get_simple_config_google_dns(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config, ActorOwn<> get_simple_config_google_dns(Promise<SimpleConfigResult> promise, const Global *shared_config, bool is_test,
bool is_test, int32 scheduler_id);
ActorOwn<> get_simple_config_mozilla_dns(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config,
bool is_test, int32 scheduler_id);
ActorOwn<> get_simple_config_firebase_remote_config(Promise<SimpleConfigResult> promise,
const ConfigShared *shared_config, bool is_test,
int32 scheduler_id); int32 scheduler_id);
ActorOwn<> get_simple_config_firebase_realtime(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config, ActorOwn<> get_simple_config_mozilla_dns(Promise<SimpleConfigResult> promise, const Global *shared_config, bool is_test,
int32 scheduler_id);
ActorOwn<> get_simple_config_firebase_remote_config(Promise<SimpleConfigResult> promise, const Global *shared_config,
bool is_test, int32 scheduler_id); bool is_test, int32 scheduler_id);
ActorOwn<> get_simple_config_firebase_firestore(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config, ActorOwn<> get_simple_config_firebase_realtime(Promise<SimpleConfigResult> promise, const Global *shared_config,
bool is_test, int32 scheduler_id);
ActorOwn<> get_simple_config_firebase_firestore(Promise<SimpleConfigResult> promise, const Global *shared_config,
bool is_test, int32 scheduler_id); bool is_test, int32 scheduler_id);
class HttpDate { class HttpDate {

View File

@ -11,7 +11,6 @@
#include "td/telegram/BotMenuButton.h" #include "td/telegram/BotMenuButton.h"
#include "td/telegram/ChannelParticipantFilter.h" #include "td/telegram/ChannelParticipantFilter.h"
#include "td/telegram/ConfigManager.h" #include "td/telegram/ConfigManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/Dependencies.h" #include "td/telegram/Dependencies.h"
#include "td/telegram/DialogInviteLink.h" #include "td/telegram/DialogInviteLink.h"
#include "td/telegram/DialogLocation.h" #include "td/telegram/DialogLocation.h"
@ -3333,11 +3332,11 @@ ContactsManager::ContactsManager(Td *td, ActorShared<> parent) : td_(td), parent
my_id_ = load_my_id(); my_id_ = load_my_id();
G()->shared_config().set_option_integer("telegram_service_notifications_chat_id", G()->set_option_integer("telegram_service_notifications_chat_id",
DialogId(get_service_notifications_user_id()).get()); DialogId(get_service_notifications_user_id()).get());
G()->shared_config().set_option_integer("replies_bot_chat_id", DialogId(get_replies_bot_user_id()).get()); G()->set_option_integer("replies_bot_chat_id", DialogId(get_replies_bot_user_id()).get());
G()->shared_config().set_option_integer("group_anonymous_bot_user_id", get_anonymous_bot_user_id().get()); G()->set_option_integer("group_anonymous_bot_user_id", get_anonymous_bot_user_id().get());
G()->shared_config().set_option_integer("channel_bot_user_id", get_channel_bot_user_id().get()); G()->set_option_integer("channel_bot_user_id", get_channel_bot_user_id().get());
if (G()->parameters().use_chat_info_db) { if (G()->parameters().use_chat_info_db) {
auto next_contacts_sync_date_string = G()->td_db()->get_binlog_pmc()->get("next_contacts_sync_date"); auto next_contacts_sync_date_string = G()->td_db()->get_binlog_pmc()->get("next_contacts_sync_date");
@ -5099,7 +5098,7 @@ void ContactsManager::set_my_id(UserId my_id) {
if (my_old_id != my_id) { if (my_old_id != my_id) {
my_id_ = my_id; my_id_ = my_id;
G()->td_db()->get_binlog_pmc()->set("my_id", to_string(my_id.get())); G()->td_db()->get_binlog_pmc()->set("my_id", to_string(my_id.get()));
G()->shared_config().set_option_integer("my_id", my_id_.get()); G()->set_option_integer("my_id", my_id_.get());
G()->td_db()->get_binlog_pmc()->force_sync(Promise<Unit>()); G()->td_db()->get_binlog_pmc()->force_sync(Promise<Unit>());
} }
} }
@ -6037,7 +6036,7 @@ void ContactsManager::set_location(const Location &location, Promise<Unit> &&pro
} }
void ContactsManager::set_location_visibility() { void ContactsManager::set_location_visibility() {
bool is_location_visible = G()->shared_config().get_option_boolean("is_location_visible"); bool is_location_visible = G()->get_option_boolean("is_location_visible");
auto pending_location_visibility_expire_date = is_location_visible ? std::numeric_limits<int32>::max() : 0; auto pending_location_visibility_expire_date = is_location_visible ? std::numeric_limits<int32>::max() : 0;
if (pending_location_visibility_expire_date_ == -1 && if (pending_location_visibility_expire_date_ == -1 &&
pending_location_visibility_expire_date == location_visibility_expire_date_) { pending_location_visibility_expire_date == location_visibility_expire_date_) {
@ -6260,7 +6259,7 @@ void ContactsManager::set_location_visibility_expire_date(int32 expire_date) {
void ContactsManager::update_is_location_visible() { void ContactsManager::update_is_location_visible() {
auto expire_date = pending_location_visibility_expire_date_ != -1 ? pending_location_visibility_expire_date_ auto expire_date = pending_location_visibility_expire_date_ != -1 ? pending_location_visibility_expire_date_
: location_visibility_expire_date_; : location_visibility_expire_date_;
G()->shared_config().set_option_boolean("is_location_visible", expire_date != 0); G()->set_option_boolean("is_location_visible", expire_date != 0);
} }
void ContactsManager::on_update_bot_commands(DialogId dialog_id, UserId bot_user_id, void ContactsManager::on_update_bot_commands(DialogId dialog_id, UserId bot_user_id,
@ -6490,7 +6489,7 @@ void ContactsManager::set_name(const string &first_name, const string &last_name
} }
void ContactsManager::set_bio(const string &bio, Promise<Unit> &&promise) { void ContactsManager::set_bio(const string &bio, Promise<Unit> &&promise) {
auto max_bio_length = static_cast<size_t>(G()->shared_config().get_option_integer("bio_length_max")); auto max_bio_length = static_cast<size_t>(G()->get_option_integer("bio_length_max"));
auto new_bio = strip_empty_characters(bio, max_bio_length); auto new_bio = strip_empty_characters(bio, max_bio_length);
for (auto &c : new_bio) { for (auto &c : new_bio) {
if (c == '\n') { if (c == '\n') {
@ -8612,7 +8611,7 @@ void ContactsManager::on_get_user(tl_object_ptr<telegram_api::User> &&user_ptr,
if (flags & USER_FLAG_IS_ME) { if (flags & USER_FLAG_IS_ME) {
set_my_id(user_id); set_my_id(user_id);
if (!is_bot) { if (!is_bot) {
G()->shared_config().set_option_string("my_phone_number", user->phone_); G()->set_option_string("my_phone_number", user->phone_);
} }
} }
@ -10191,8 +10190,8 @@ void ContactsManager::for_each_secret_chat_with_user(UserId user_id, const std::
void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, bool from_database) { void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, bool from_database) {
CHECK(u != nullptr); CHECK(u != nullptr);
if (user_id == get_my_id()) { if (user_id == get_my_id()) {
if (G()->shared_config().get_option_boolean("is_premium") != u->is_premium) { if (G()->get_option_boolean("is_premium") != u->is_premium) {
G()->shared_config().set_option_boolean("is_premium", u->is_premium); G()->set_option_boolean("is_premium", u->is_premium);
send_closure(td_->config_manager_, &ConfigManager::request_config, true); send_closure(td_->config_manager_, &ConfigManager::request_config, true);
} }
} }

View File

@ -6,7 +6,6 @@
// //
#include "td/telegram/DialogFilter.h" #include "td/telegram/DialogFilter.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/DialogId.h" #include "td/telegram/DialogId.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
@ -20,7 +19,7 @@
namespace td { namespace td {
int32 DialogFilter::get_max_filter_dialogs() { int32 DialogFilter::get_max_filter_dialogs() {
return narrow_cast<int32>(G()->shared_config().get_option_integer("chat_filter_chosen_chat_count_max", 100)); return narrow_cast<int32>(G()->get_option_integer("chat_filter_chosen_chat_count_max", 100));
} }
unique_ptr<DialogFilter> DialogFilter::get_dialog_filter( unique_ptr<DialogFilter> DialogFilter::get_dialog_filter(

View File

@ -256,6 +256,46 @@ void Global::set_shared_config(unique_ptr<ConfigShared> shared_config) {
shared_config_ = std::move(shared_config); shared_config_ = std::move(shared_config);
} }
void Global::set_option_empty(Slice name) {
shared_config_->set_option_empty(name);
}
void Global::set_option_boolean(Slice name, bool value) {
shared_config_->set_option_boolean(name, value);
}
void Global::set_option_integer(Slice name, int64 value) {
shared_config_->set_option_integer(name, value);
}
void Global::set_option_string(Slice name, Slice value) {
shared_config_->set_option_string(name, value);
}
bool Global::have_option(Slice name) const {
return shared_config_->have_option(name);
}
string Global::get_option(Slice name) const {
return shared_config_->get_option(name);
}
std::unordered_map<string, string> Global::get_options() const {
return shared_config_->get_options();
}
bool Global::get_option_boolean(Slice name, bool default_value) const {
return shared_config_->get_option_integer(name, default_value);
}
int64 Global::get_option_integer(Slice name, int64 default_value) const {
return shared_config_->get_option_integer(name, default_value);
}
string Global::get_option_string(Slice name, string default_value) const {
return shared_config_->get_option_string(name, std::move(default_value));
}
int64 Global::get_location_key(double latitude, double longitude) { int64 Global::get_location_key(double latitude, double longitude) {
const double PI = 3.14159265358979323846; const double PI = 3.14159265358979323846;
latitude *= PI / 180; latitude *= PI / 180;

View File

@ -28,6 +28,7 @@
#include <atomic> #include <atomic>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <unordered_map>
namespace td { namespace td {
@ -129,10 +130,25 @@ class Global final : public ActorContext {
void set_shared_config(unique_ptr<ConfigShared> shared_config); void set_shared_config(unique_ptr<ConfigShared> shared_config);
ConfigShared &shared_config() { void set_option_empty(Slice name);
CHECK(shared_config_.get() != nullptr);
return *shared_config_; void set_option_boolean(Slice name, bool value);
}
void set_option_integer(Slice name, int64 value);
void set_option_string(Slice name, Slice value);
bool have_option(Slice name) const;
string get_option(Slice name) const;
std::unordered_map<string, string> get_options() const;
bool get_option_boolean(Slice name, bool default_value = false) const;
int64 get_option_integer(Slice name, int64 default_value = 0) const;
string get_option_string(Slice name, string default_value = "") const;
bool is_server_time_reliable() const { bool is_server_time_reliable() const {
return server_time_difference_was_updated_; return server_time_difference_was_updated_;

View File

@ -6,7 +6,6 @@
// //
#include "td/telegram/LanguagePackManager.h" #include "td/telegram/LanguagePackManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
#include "td/telegram/logevent/LogEvent.h" #include "td/telegram/logevent/LogEvent.h"
#include "td/telegram/misc.h" #include "td/telegram/misc.h"
@ -202,12 +201,12 @@ LanguagePackManager::LanguageDatabase *LanguagePackManager::add_language_databas
void LanguagePackManager::start_up() { void LanguagePackManager::start_up() {
std::lock_guard<std::mutex> database_lock(language_database_mutex_); std::lock_guard<std::mutex> database_lock(language_database_mutex_);
manager_count_++; manager_count_++;
language_pack_ = G()->shared_config().get_option_string("localization_target"); language_pack_ = G()->get_option_string("localization_target");
language_code_ = G()->shared_config().get_option_string("language_pack_id"); language_code_ = G()->get_option_string("language_pack_id");
CHECK(check_language_pack_name(language_pack_)); CHECK(check_language_pack_name(language_pack_));
CHECK(check_language_code_name(language_code_)); CHECK(check_language_code_name(language_code_));
database_ = add_language_database(G()->shared_config().get_option_string("language_pack_database_path")); database_ = add_language_database(G()->get_option_string("language_pack_database_path"));
if (!language_pack_.empty() && !language_code_.empty()) { if (!language_pack_.empty() && !language_code_.empty()) {
auto language = add_language(database_, language_pack_, language_code_); auto language = add_language(database_, language_pack_, language_code_);
if (language->version_ == -1) { if (language->version_ == -1) {
@ -339,7 +338,7 @@ vector<string> LanguagePackManager::get_used_language_codes() {
} }
void LanguagePackManager::on_language_pack_changed() { void LanguagePackManager::on_language_pack_changed() {
auto new_language_pack = G()->shared_config().get_option_string("localization_target"); auto new_language_pack = G()->get_option_string("localization_target");
if (new_language_pack == language_pack_) { if (new_language_pack == language_pack_) {
return; return;
} }
@ -350,7 +349,7 @@ void LanguagePackManager::on_language_pack_changed() {
} }
void LanguagePackManager::on_language_code_changed() { void LanguagePackManager::on_language_code_changed() {
auto new_language_code = G()->shared_config().get_option_string("language_pack_id"); auto new_language_code = G()->get_option_string("language_pack_id");
if (new_language_code == language_code_) { if (new_language_code == language_code_) {
return; return;
} }
@ -374,7 +373,7 @@ void LanguagePackManager::on_language_pack_version_changed(bool is_base, int32 n
if (new_version < 0) { if (new_version < 0) {
Slice version_key = is_base ? Slice("base_language_pack_version") : Slice("language_pack_version"); Slice version_key = is_base ? Slice("base_language_pack_version") : Slice("language_pack_version");
new_version = narrow_cast<int32>(G()->shared_config().get_option_integer(version_key, -1)); new_version = narrow_cast<int32>(G()->get_option_integer(version_key, -1));
} }
if (new_version <= 0) { if (new_version <= 0) {
return; return;
@ -495,8 +494,8 @@ void LanguagePackManager::on_update_language_pack(tl_object_ptr<telegram_api::la
} }
void LanguagePackManager::inc_generation() { void LanguagePackManager::inc_generation() {
G()->shared_config().set_option_empty("language_pack_version"); G()->set_option_empty("language_pack_version");
G()->shared_config().set_option_empty("base_language_pack_version"); G()->set_option_empty("base_language_pack_version");
if (!language_pack_.empty() && !language_code_.empty()) { if (!language_pack_.empty() && !language_code_.empty()) {
LOG(INFO) << "Add main language " << language_code_; LOG(INFO) << "Add main language " << language_code_;
@ -946,7 +945,7 @@ void LanguagePackManager::on_get_language_info(const string &language_pack,
} }
} }
if (was_updated_base_language_code) { if (was_updated_base_language_code) {
G()->shared_config().set_option_empty("base_language_pack_version"); G()->set_option_empty("base_language_pack_version");
if (!base_language_code_.empty()) { if (!base_language_code_.empty()) {
add_language(database_, language_pack_, base_language_code_); add_language(database_, language_pack_, base_language_code_);
on_language_pack_version_changed(true, std::numeric_limits<int32>::max()); on_language_pack_version_changed(true, std::numeric_limits<int32>::max());

View File

@ -10,7 +10,6 @@
#include "td/telegram/ChannelId.h" #include "td/telegram/ChannelId.h"
#include "td/telegram/ChannelType.h" #include "td/telegram/ChannelType.h"
#include "td/telegram/ConfigManager.h" #include "td/telegram/ConfigManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ContactsManager.h" #include "td/telegram/ContactsManager.h"
#include "td/telegram/DialogId.h" #include "td/telegram/DialogId.h"
#include "td/telegram/DialogParticipant.h" #include "td/telegram/DialogParticipant.h"
@ -254,8 +253,7 @@ class LinkManager::InternalLinkBotStart final : public InternalLink {
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final { td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
bool autostart = autostart_; bool autostart = autostart_;
if (Scheduler::context() != nullptr && if (Scheduler::context() != nullptr && bot_username_ == G()->get_option_string("premium_bot_username")) {
bot_username_ == G()->shared_config().get_option_string("premium_bot_username")) {
autostart = true; autostart = true;
} }
return td_api::make_object<td_api::internalLinkTypeBotStart>(bot_username_, start_parameter_, autostart); return td_api::make_object<td_api::internalLinkTypeBotStart>(bot_username_, start_parameter_, autostart);
@ -889,7 +887,7 @@ LinkManager::LinkInfo LinkManager::get_link_info(Slice link) {
vector<Slice> t_me_urls{Slice("t.me"), Slice("telegram.me"), Slice("telegram.dog")}; vector<Slice> t_me_urls{Slice("t.me"), Slice("telegram.me"), Slice("telegram.dog")};
if (Scheduler::context() != nullptr) { // for tests only if (Scheduler::context() != nullptr) { // for tests only
string cur_t_me_url = G()->shared_config().get_option_string("t_me_url"); string cur_t_me_url = G()->get_option_string("t_me_url");
if (tolower_begins_with(cur_t_me_url, "http://") || tolower_begins_with(cur_t_me_url, "https://")) { if (tolower_begins_with(cur_t_me_url, "http://") || tolower_begins_with(cur_t_me_url, "https://")) {
Slice t_me_url = cur_t_me_url; Slice t_me_url = cur_t_me_url;
t_me_url = t_me_url.substr(t_me_url[4] == 's' ? 8 : 7); t_me_url = t_me_url.substr(t_me_url[4] == 's' ? 8 : 7);
@ -1570,7 +1568,7 @@ string LinkManager::get_dialog_invite_link(Slice hash, bool is_internal) {
if (is_internal) { if (is_internal) {
return PSTRING() << "tg:join?invite=" << hash; return PSTRING() << "tg:join?invite=" << hash;
} else { } else {
return PSTRING() << G()->shared_config().get_option_string("t_me_url", "https://t.me/") << '+' << hash; return PSTRING() << G()->get_option_string("t_me_url", "https://t.me/") << '+' << hash;
} }
} }

View File

@ -14,7 +14,6 @@
#include "td/telegram/CallDiscardReason.h" #include "td/telegram/CallDiscardReason.h"
#include "td/telegram/ChannelId.h" #include "td/telegram/ChannelId.h"
#include "td/telegram/ChatId.h" #include "td/telegram/ChatId.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/Contact.h" #include "td/telegram/Contact.h"
#include "td/telegram/ContactsManager.h" #include "td/telegram/ContactsManager.h"
#include "td/telegram/Dependencies.h" #include "td/telegram/Dependencies.h"
@ -4671,7 +4670,7 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
} }
case MessageContentType::Sticker: { case MessageContentType::Sticker: {
auto result = make_unique<MessageSticker>(*static_cast<const MessageSticker *>(content)); auto result = make_unique<MessageSticker>(*static_cast<const MessageSticker *>(content));
result->is_premium = G()->shared_config().get_option_boolean("is_premium"); result->is_premium = G()->get_option_boolean("is_premium");
if (td->stickers_manager_->has_input_media(result->file_id, to_secret)) { if (td->stickers_manager_->has_input_media(result->file_id, to_secret)) {
return std::move(result); return std::move(result);
} }

View File

@ -6,7 +6,6 @@
// //
#include "td/telegram/MessageEntity.h" #include "td/telegram/MessageEntity.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ContactsManager.h" #include "td/telegram/ContactsManager.h"
#include "td/telegram/Dependencies.h" #include "td/telegram/Dependencies.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
@ -4305,7 +4304,7 @@ Result<FormattedText> get_formatted_text(const Td *td, DialogId dialog_id,
TRY_RESULT(entities, get_message_entities(td->contacts_manager_.get(), std::move(text->entities_))); TRY_RESULT(entities, get_message_entities(td->contacts_manager_.get(), std::move(text->entities_)));
auto need_skip_bot_commands = need_always_skip_bot_commands(td->contacts_manager_.get(), dialog_id, is_bot); auto need_skip_bot_commands = need_always_skip_bot_commands(td->contacts_manager_.get(), dialog_id, is_bot);
bool parse_markdown = G()->shared_config().get_option_boolean("always_parse_markdown"); bool parse_markdown = G()->get_option_boolean("always_parse_markdown");
TRY_STATUS(fix_formatted_text(text->text_, entities, allow_empty, parse_markdown, need_skip_bot_commands, TRY_STATUS(fix_formatted_text(text->text_, entities, allow_empty, parse_markdown, need_skip_bot_commands,
is_bot || skip_media_timestamps || parse_markdown, for_draft)); is_bot || skip_media_timestamps || parse_markdown, for_draft));
@ -4495,8 +4494,7 @@ void remove_unallowed_entities(const Td *td, FormattedText &text, DialogId dialo
remove_intersecting_entities(text.entities); remove_intersecting_entities(text.entities);
} }
} }
if (!G()->shared_config().get_option_boolean("is_premium") && if (!G()->get_option_boolean("is_premium") && dialog_id != DialogId(td->contacts_manager_->get_my_id())) {
dialog_id != DialogId(td->contacts_manager_->get_my_id())) {
remove_premium_custom_emoji_entities(td, text.entities, false); remove_premium_custom_emoji_entities(td, text.entities, false);
} }
} }

View File

@ -8,7 +8,6 @@
#include "td/telegram/AccessRights.h" #include "td/telegram/AccessRights.h"
#include "td/telegram/ConfigManager.h" #include "td/telegram/ConfigManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ContactsManager.h" #include "td/telegram/ContactsManager.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
#include "td/telegram/MessageSender.h" #include "td/telegram/MessageSender.h"
@ -241,13 +240,13 @@ class SetDefaultReactionQuery final : public Td::ResultHandler {
return on_error(Status::Error(400, "Receive false")); return on_error(Status::Error(400, "Receive false"));
} }
auto default_reaction = G()->shared_config().get_option_string("default_reaction", "-"); auto default_reaction = G()->get_option_string("default_reaction", "-");
LOG(INFO) << "Successfully set reaction " << reaction_ << " as default, current default is " << default_reaction; LOG(INFO) << "Successfully set reaction " << reaction_ << " as default, current default is " << default_reaction;
if (default_reaction != reaction_) { if (default_reaction != reaction_) {
send_set_default_reaction_query(td_); send_set_default_reaction_query(td_);
} else { } else {
G()->shared_config().set_option_empty("default_reaction_needs_sync"); G()->set_option_empty("default_reaction_needs_sync");
} }
} }
@ -257,7 +256,7 @@ class SetDefaultReactionQuery final : public Td::ResultHandler {
} }
LOG(INFO) << "Failed to set default reaction: " << status; LOG(INFO) << "Failed to set default reaction: " << status;
G()->shared_config().set_option_empty("default_reaction_needs_sync"); G()->set_option_empty("default_reaction_needs_sync");
send_closure(G()->config_manager(), &ConfigManager::reget_app_config, Promise<Unit>()); send_closure(G()->config_manager(), &ConfigManager::reget_app_config, Promise<Unit>());
} }
}; };
@ -595,17 +594,17 @@ void set_default_reaction(Td *td, string reaction, Promise<Unit> &&promise) {
return promise.set_error(Status::Error(400, "Can't set incative reaction as default")); return promise.set_error(Status::Error(400, "Can't set incative reaction as default"));
} }
if (G()->shared_config().get_option_string("default_reaction", "-") != reaction) { if (G()->get_option_string("default_reaction", "-") != reaction) {
G()->shared_config().set_option_string("default_reaction", reaction); G()->set_option_string("default_reaction", reaction);
if (!G()->shared_config().get_option_boolean("default_reaction_needs_sync")) { if (!G()->get_option_boolean("default_reaction_needs_sync")) {
G()->shared_config().set_option_boolean("default_reaction_needs_sync", true); G()->set_option_boolean("default_reaction_needs_sync", true);
} }
} }
promise.set_value(Unit()); promise.set_value(Unit());
} }
void send_set_default_reaction_query(Td *td) { void send_set_default_reaction_query(Td *td) {
td->create_handler<SetDefaultReactionQuery>()->send(G()->shared_config().get_option_string("default_reaction")); td->create_handler<SetDefaultReactionQuery>()->send(G()->get_option_string("default_reaction"));
} }
} // namespace td } // namespace td

View File

@ -10,7 +10,6 @@
#include "td/telegram/ChainId.h" #include "td/telegram/ChainId.h"
#include "td/telegram/ChannelType.h" #include "td/telegram/ChannelType.h"
#include "td/telegram/ChatId.h" #include "td/telegram/ChatId.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ContactsManager.h" #include "td/telegram/ContactsManager.h"
#include "td/telegram/Dependencies.h" #include "td/telegram/Dependencies.h"
#include "td/telegram/DialogActionBar.h" #include "td/telegram/DialogActionBar.h"
@ -3212,7 +3211,7 @@ class SendMessageQuery final : public Td::ResultHandler {
std::move(reply_markup), std::move(entities), schedule_date, std::move(as_input_peer)), std::move(reply_markup), std::move(entities), schedule_date, std::move(as_input_peer)),
{{dialog_id, MessageContentType::Text}, {{dialog_id, MessageContentType::Text},
{dialog_id, is_copy ? MessageContentType::Photo : MessageContentType::Text}}); {dialog_id, is_copy ? MessageContentType::Photo : MessageContentType::Text}});
if (G()->shared_config().get_option_boolean("use_quick_ack")) { if (G()->get_option_boolean("use_quick_ack")) {
query->quick_ack_promise_ = PromiseCreator::lambda([random_id](Result<Unit> result) { query->quick_ack_promise_ = PromiseCreator::lambda([random_id](Result<Unit> result) {
if (result.is_ok()) { if (result.is_ok()) {
send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id); send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id);
@ -3283,7 +3282,7 @@ class StartBotQuery final : public Td::ResultHandler {
auto query = G()->net_query_creator().create( auto query = G()->net_query_creator().create(
telegram_api::messages_startBot(std::move(bot_input_user), std::move(input_peer), random_id, parameter), telegram_api::messages_startBot(std::move(bot_input_user), std::move(input_peer), random_id, parameter),
{{dialog_id, MessageContentType::Text}, {dialog_id, MessageContentType::Photo}}); {{dialog_id, MessageContentType::Text}, {dialog_id, MessageContentType::Photo}});
if (G()->shared_config().get_option_boolean("use_quick_ack")) { if (G()->get_option_boolean("use_quick_ack")) {
query->quick_ack_promise_ = PromiseCreator::lambda([random_id](Result<Unit> result) { query->quick_ack_promise_ = PromiseCreator::lambda([random_id](Result<Unit> result) {
if (result.is_ok()) { if (result.is_ok()) {
send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id); send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id);
@ -3525,7 +3524,7 @@ class SendMediaQuery final : public Td::ResultHandler {
reply_to_message_id.get_server_message_id().get(), std::move(input_media), text, random_id, reply_to_message_id.get_server_message_id().get(), std::move(input_media), text, random_id,
std::move(reply_markup), std::move(entities), schedule_date, std::move(as_input_peer)), std::move(reply_markup), std::move(entities), schedule_date, std::move(as_input_peer)),
{{dialog_id, content_type}, {dialog_id, is_copy ? MessageContentType::Text : content_type}}); {{dialog_id, content_type}, {dialog_id, is_copy ? MessageContentType::Text : content_type}});
if (G()->shared_config().get_option_boolean("use_quick_ack") && was_uploaded_) { if (G()->get_option_boolean("use_quick_ack") && was_uploaded_) {
query->quick_ack_promise_ = PromiseCreator::lambda([random_id](Result<Unit> result) { query->quick_ack_promise_ = PromiseCreator::lambda([random_id](Result<Unit> result) {
if (result.is_ok()) { if (result.is_ok()) {
send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id); send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id);
@ -3889,7 +3888,7 @@ class ForwardMessagesQuery final : public Td::ResultHandler {
false /*ignored*/, std::move(from_input_peer), MessagesManager::get_server_message_ids(message_ids), false /*ignored*/, std::move(from_input_peer), MessagesManager::get_server_message_ids(message_ids),
std::move(random_ids), std::move(to_input_peer), schedule_date, std::move(as_input_peer)), std::move(random_ids), std::move(to_input_peer), schedule_date, std::move(as_input_peer)),
{{to_dialog_id, MessageContentType::Text}, {to_dialog_id, MessageContentType::Photo}}); {{to_dialog_id, MessageContentType::Text}, {to_dialog_id, MessageContentType::Photo}});
if (G()->shared_config().get_option_boolean("use_quick_ack")) { if (G()->get_option_boolean("use_quick_ack")) {
query->quick_ack_promise_ = PromiseCreator::lambda([random_ids = random_ids_](Result<Unit> result) { query->quick_ack_promise_ = PromiseCreator::lambda([random_ids = random_ids_](Result<Unit> result) {
if (result.is_ok()) { if (result.is_ok()) {
for (auto random_id : random_ids) { for (auto random_id : random_ids) {
@ -10696,9 +10695,8 @@ bool MessagesManager::can_revoke_message(DialogId dialog_id, const Message *m) c
auto content_type = m->content->get_type(); auto content_type = m->content->get_type();
switch (dialog_id.get_type()) { switch (dialog_id.get_type()) {
case DialogType::User: { case DialogType::User: {
bool can_revoke_incoming = G()->shared_config().get_option_boolean("revoke_pm_inbox", true); bool can_revoke_incoming = G()->get_option_boolean("revoke_pm_inbox", true);
int64 revoke_time_limit = int64 revoke_time_limit = G()->get_option_integer("revoke_pm_time_limit", DEFAULT_REVOKE_TIME_LIMIT);
G()->shared_config().get_option_integer("revoke_pm_time_limit", DEFAULT_REVOKE_TIME_LIMIT);
if (G()->unix_time_cached() - m->date < 86400 && content_type == MessageContentType::Dice) { if (G()->unix_time_cached() - m->date < 86400 && content_type == MessageContentType::Dice) {
return false; return false;
@ -10710,7 +10708,7 @@ bool MessagesManager::can_revoke_message(DialogId dialog_id, const Message *m) c
case DialogType::Chat: { case DialogType::Chat: {
bool is_appointed_administrator = bool is_appointed_administrator =
td_->contacts_manager_->is_appointed_chat_administrator(dialog_id.get_chat_id()); td_->contacts_manager_->is_appointed_chat_administrator(dialog_id.get_chat_id());
int64 revoke_time_limit = G()->shared_config().get_option_integer("revoke_time_limit", DEFAULT_REVOKE_TIME_LIMIT); int64 revoke_time_limit = G()->get_option_integer("revoke_time_limit", DEFAULT_REVOKE_TIME_LIMIT);
return ((m->is_outgoing && !is_service_message_content(content_type)) || is_appointed_administrator) && return ((m->is_outgoing && !is_service_message_content(content_type)) || is_appointed_administrator) &&
G()->unix_time_cached() - m->date <= revoke_time_limit; G()->unix_time_cached() - m->date <= revoke_time_limit;
@ -11048,7 +11046,7 @@ MessagesManager::CanDeleteDialog MessagesManager::can_delete_dialog(const Dialog
td_->contacts_manager_->is_user_bot(d->dialog_id.get_user_id())) { td_->contacts_manager_->is_user_bot(d->dialog_id.get_user_id())) {
return {true, false}; return {true, false};
} }
return {true, G()->shared_config().get_option_boolean("revoke_pm_inbox", true)}; return {true, G()->get_option_boolean("revoke_pm_inbox", true)};
case DialogType::Chat: case DialogType::Chat:
// chats can be deleted only for self and can be deleted for everyone by their creator // chats can be deleted only for self and can be deleted for everyone by their creator
return {true, td_->contacts_manager_->get_chat_status(d->dialog_id.get_chat_id()).is_creator()}; return {true, td_->contacts_manager_->get_chat_status(d->dialog_id.get_chat_id()).is_creator()};
@ -11586,7 +11584,7 @@ int32 MessagesManager::get_unload_dialog_delay() const {
CHECK(is_message_unload_enabled()); CHECK(is_message_unload_enabled());
auto default_unload_delay = td_->auth_manager_->is_bot() ? DIALOG_UNLOAD_BOT_DELAY : DIALOG_UNLOAD_DELAY; auto default_unload_delay = td_->auth_manager_->is_bot() ? DIALOG_UNLOAD_BOT_DELAY : DIALOG_UNLOAD_DELAY;
return narrow_cast<int32>(G()->shared_config().get_option_integer("message_unload_delay", default_unload_delay)); return narrow_cast<int32>(G()->get_option_integer("message_unload_delay", default_unload_delay));
} }
int32 MessagesManager::get_next_unload_dialog_delay() const { int32 MessagesManager::get_next_unload_dialog_delay() const {
@ -13182,7 +13180,7 @@ void MessagesManager::init() {
if (is_authorized && td_->auth_manager_->is_bot()) { if (is_authorized && td_->auth_manager_->is_bot()) {
disable_get_dialog_filter_ = true; disable_get_dialog_filter_ = true;
} }
authorization_date_ = G()->shared_config().get_option_integer("authorization_date"); authorization_date_ = G()->get_option_integer("authorization_date");
if (was_authorized_user) { if (was_authorized_user) {
auto dialog_filters = G()->td_db()->get_binlog_pmc()->get("dialog_filters"); auto dialog_filters = G()->td_db()->get_binlog_pmc()->get("dialog_filters");
@ -13191,7 +13189,7 @@ void MessagesManager::init() {
if (log_event_parse(log_event, dialog_filters).is_ok()) { if (log_event_parse(log_event, dialog_filters).is_ok()) {
server_main_dialog_list_position_ = log_event.server_main_dialog_list_position; server_main_dialog_list_position_ = log_event.server_main_dialog_list_position;
main_dialog_list_position_ = log_event.main_dialog_list_position; main_dialog_list_position_ = log_event.main_dialog_list_position;
if (!G()->shared_config().get_option_boolean("is_premium") && if (!G()->get_option_boolean("is_premium") &&
(server_main_dialog_list_position_ != 0 || main_dialog_list_position_ != 0)) { (server_main_dialog_list_position_ != 0 || main_dialog_list_position_ != 0)) {
LOG(INFO) << "Ignore main chat list position " << server_main_dialog_list_position_ << '/' LOG(INFO) << "Ignore main chat list position " << server_main_dialog_list_position_ << '/'
<< main_dialog_list_position_; << main_dialog_list_position_;
@ -13583,7 +13581,7 @@ void MessagesManager::init() {
void MessagesManager::on_authorization_success() { void MessagesManager::on_authorization_success() {
CHECK(td_->auth_manager_->is_authorized()); CHECK(td_->auth_manager_->is_authorized());
authorization_date_ = G()->shared_config().get_option_integer("authorization_date"); authorization_date_ = G()->get_option_integer("authorization_date");
if (td_->auth_manager_->is_bot()) { if (td_->auth_manager_->is_bot()) {
disable_get_dialog_filter_ = true; disable_get_dialog_filter_ = true;
@ -17259,7 +17257,7 @@ void MessagesManager::on_get_dialog_filters(Result<vector<tl_object_ptr<telegram
LOG(ERROR) << "Receive no dialogFilterDefault"; LOG(ERROR) << "Receive no dialogFilterDefault";
server_main_dialog_list_position = 0; server_main_dialog_list_position = 0;
} }
if (server_main_dialog_list_position != 0 && !G()->shared_config().get_option_boolean("is_premium")) { if (server_main_dialog_list_position != 0 && !G()->get_option_boolean("is_premium")) {
LOG(INFO) << "Ignore server main chat list position " << server_main_dialog_list_position; LOG(INFO) << "Ignore server main chat list position " << server_main_dialog_list_position;
server_main_dialog_list_position = 0; server_main_dialog_list_position = 0;
} }
@ -18294,7 +18292,7 @@ Status MessagesManager::can_get_message_viewers(DialogId dialog_id, const Messag
if (!m->is_outgoing) { if (!m->is_outgoing) {
return Status::Error(400, "Can't get viewers of incoming messages"); return Status::Error(400, "Can't get viewers of incoming messages");
} }
if (G()->unix_time() - m->date > G()->shared_config().get_option_integer("chat_read_mark_expire_period", 7 * 86400)) { if (G()->unix_time() - m->date > G()->get_option_integer("chat_read_mark_expire_period", 7 * 86400)) {
return Status::Error(400, "Message is too old"); return Status::Error(400, "Message is too old");
} }
@ -18327,7 +18325,7 @@ Status MessagesManager::can_get_message_viewers(DialogId dialog_id, const Messag
if (participant_count == 0) { if (participant_count == 0) {
return Status::Error(400, "Chat is empty or have unknown number of members"); return Status::Error(400, "Chat is empty or have unknown number of members");
} }
if (participant_count > G()->shared_config().get_option_integer("chat_read_mark_size_threshold", 100)) { if (participant_count > G()->get_option_integer("chat_read_mark_size_threshold", 100)) {
return Status::Error(400, "Chat is too big"); return Status::Error(400, "Chat is too big");
} }
@ -18745,7 +18743,7 @@ Result<std::pair<string, bool>> MessagesManager::get_message_link(FullMessageId
} }
SliceBuilder sb; SliceBuilder sb;
sb << G()->shared_config().get_option_string("t_me_url", "https://t.me/"); sb << G()->get_option_string("t_me_url", "https://t.me/");
if (for_comment) { if (for_comment) {
auto *top_m = get_message_force(d, m->top_thread_message_id, "get_public_message_link"); auto *top_m = get_message_force(d, m->top_thread_message_id, "get_public_message_link");
@ -19126,8 +19124,8 @@ Result<unique_ptr<DialogFilter>> MessagesManager::create_dialog_filter(DialogFil
void MessagesManager::create_dialog_filter(td_api::object_ptr<td_api::chatFilter> filter, void MessagesManager::create_dialog_filter(td_api::object_ptr<td_api::chatFilter> filter,
Promise<td_api::object_ptr<td_api::chatFilterInfo>> &&promise) { Promise<td_api::object_ptr<td_api::chatFilterInfo>> &&promise) {
CHECK(!td_->auth_manager_->is_bot()); CHECK(!td_->auth_manager_->is_bot());
auto max_dialog_filters = clamp(G()->shared_config().get_option_integer("chat_filter_count_max"), auto max_dialog_filters =
static_cast<int64>(0), static_cast<int64>(100)); clamp(G()->get_option_integer("chat_filter_count_max"), static_cast<int64>(0), static_cast<int64>(100));
if (dialog_filters_.size() >= narrow_cast<size_t>(max_dialog_filters)) { if (dialog_filters_.size() >= narrow_cast<size_t>(max_dialog_filters)) {
return promise.set_error(Status::Error(400, "The maximum number of chat folders exceeded")); return promise.set_error(Status::Error(400, "The maximum number of chat folders exceeded"));
} }
@ -19298,7 +19296,7 @@ void MessagesManager::reorder_dialog_filters(vector<DialogFilterId> dialog_filte
if (main_dialog_list_position < 0 || main_dialog_list_position > static_cast<int32>(dialog_filters_.size())) { if (main_dialog_list_position < 0 || main_dialog_list_position > static_cast<int32>(dialog_filters_.size())) {
return promise.set_error(Status::Error(400, "Invalid main chat list position specified")); return promise.set_error(Status::Error(400, "Invalid main chat list position specified"));
} }
if (!G()->shared_config().get_option_boolean("is_premium")) { if (!G()->get_option_boolean("is_premium")) {
main_dialog_list_position = 0; main_dialog_list_position = 0;
} }
@ -19880,9 +19878,9 @@ int32 MessagesManager::get_pinned_dialogs_limit(DialogListId dialog_list_id) {
key = Slice("pinned_archived_chat_count_max"); key = Slice("pinned_archived_chat_count_max");
default_limit = 100; default_limit = 100;
} }
int32 limit = clamp(narrow_cast<int32>(G()->shared_config().get_option_integer(key)), 0, 1000); int32 limit = clamp(narrow_cast<int32>(G()->get_option_integer(key)), 0, 1000);
if (limit <= 0) { if (limit <= 0) {
if (G()->shared_config().get_option_boolean("is_premium")) { if (G()->get_option_boolean("is_premium")) {
default_limit *= 2; default_limit *= 2;
} }
return default_limit; return default_limit;
@ -22231,7 +22229,7 @@ td_api::object_ptr<td_api::messageCalendar> MessagesManager::get_dialog_message_
db_query.dialog_id = dialog_id; db_query.dialog_id = dialog_id;
db_query.filter = filter; db_query.filter = filter;
db_query.from_message_id = fixed_from_message_id; db_query.from_message_id = fixed_from_message_id;
db_query.tz_offset = static_cast<int32>(G()->shared_config().get_option_integer("utc_time_offset")); db_query.tz_offset = static_cast<int32>(G()->get_option_integer("utc_time_offset"));
G()->td_db()->get_messages_db_async()->get_dialog_message_calendar(db_query, std::move(new_promise)); G()->td_db()->get_messages_db_async()->get_dialog_message_calendar(db_query, std::move(new_promise));
return {}; return {};
} }
@ -24333,8 +24331,8 @@ vector<AvailableReaction> MessagesManager::get_message_available_reactions(const
vector<AvailableReaction> result; vector<AvailableReaction> result;
if (can_use_reactions) { if (can_use_reactions) {
bool is_premium = G()->shared_config().get_option_boolean("is_premium"); bool is_premium = G()->get_option_boolean("is_premium");
int64 reactions_uniq_max = G()->shared_config().get_option_integer("reactions_uniq_max", 11); int64 reactions_uniq_max = G()->get_option_integer("reactions_uniq_max", 11);
bool can_add_new_reactions = bool can_add_new_reactions =
m->reactions == nullptr || static_cast<int64>(m->reactions->reactions_.size()) < reactions_uniq_max; m->reactions == nullptr || static_cast<int64>(m->reactions->reactions_.size()) < reactions_uniq_max;
// can add only active available reactions or remove previously set reaction // can add only active available reactions or remove previously set reaction
@ -24887,7 +24885,7 @@ unique_ptr<MessagesManager::Message> MessagesManager::create_message_to_send(
m->is_copy = is_copy || m->forward_info != nullptr; m->is_copy = is_copy || m->forward_info != nullptr;
if (td_->auth_manager_->is_bot() || options.disable_notification || if (td_->auth_manager_->is_bot() || options.disable_notification ||
G()->shared_config().get_option_boolean("ignore_default_disable_notification")) { G()->get_option_boolean("ignore_default_disable_notification")) {
m->disable_notification = options.disable_notification; m->disable_notification = options.disable_notification;
} else { } else {
m->disable_notification = d->notification_settings.silent_send_message; m->disable_notification = d->notification_settings.silent_send_message;
@ -25497,7 +25495,7 @@ Result<InputMessageContent> MessagesManager::process_input_message_content(
UserId(), copied_message->send_emoji); UserId(), copied_message->send_emoji);
} }
bool is_premium = G()->shared_config().get_option_boolean("is_premium"); bool is_premium = G()->get_option_boolean("is_premium");
TRY_RESULT(content, get_input_message_content(dialog_id, std::move(input_message_content), td_, is_premium)); TRY_RESULT(content, get_input_message_content(dialog_id, std::move(input_message_content), td_, is_premium));
if (content.ttl < 0 || content.ttl > MAX_PRIVATE_MESSAGE_TTL) { if (content.ttl < 0 || content.ttl > MAX_PRIVATE_MESSAGE_TTL) {
@ -26660,7 +26658,7 @@ bool MessagesManager::has_qts_messages(DialogId dialog_id) {
switch (dialog_id.get_type()) { switch (dialog_id.get_type()) {
case DialogType::User: case DialogType::User:
case DialogType::Chat: case DialogType::Chat:
return G()->shared_config().get_option_integer("session_count") > 1; return G()->get_option_integer("session_count") > 1;
case DialogType::Channel: case DialogType::Channel:
case DialogType::SecretChat: case DialogType::SecretChat:
return false; return false;
@ -26759,7 +26757,7 @@ bool MessagesManager::can_edit_message(DialogId dialog_id, const Message *m, boo
if (has_edit_time_limit) { if (has_edit_time_limit) {
const int32 DEFAULT_EDIT_TIME_LIMIT = 2 * 86400; const int32 DEFAULT_EDIT_TIME_LIMIT = 2 * 86400;
int64 edit_time_limit = G()->shared_config().get_option_integer("edit_time_limit", DEFAULT_EDIT_TIME_LIMIT); int64 edit_time_limit = G()->get_option_integer("edit_time_limit", DEFAULT_EDIT_TIME_LIMIT);
if (G()->unix_time_cached() - m->date - (is_editing ? 300 : 0) >= edit_time_limit) { if (G()->unix_time_cached() - m->date - (is_editing ? 300 : 0) >= edit_time_limit) {
return false; return false;
} }
@ -29264,7 +29262,7 @@ Result<MessagesManager::MessagePushNotificationInfo> MessagesManager::get_messag
} }
if (is_from_scheduled && dialog_id != get_my_dialog_id() && if (is_from_scheduled && dialog_id != get_my_dialog_id() &&
G()->shared_config().get_option_boolean("disable_sent_scheduled_message_notifications")) { G()->get_option_boolean("disable_sent_scheduled_message_notifications")) {
return Status::Error("Ignore notification about sent scheduled message"); return Status::Error("Ignore notification about sent scheduled message");
} }
@ -30127,7 +30125,7 @@ bool MessagesManager::is_message_notification_disabled(const Dialog *d, const Me
return true; return true;
} }
if (m->is_from_scheduled && d->dialog_id != get_my_dialog_id() && if (m->is_from_scheduled && d->dialog_id != get_my_dialog_id() &&
G()->shared_config().get_option_boolean("disable_sent_scheduled_message_notifications")) { G()->get_option_boolean("disable_sent_scheduled_message_notifications")) {
return true; return true;
} }
if (m->forward_info != nullptr && m->forward_info->is_imported) { if (m->forward_info != nullptr && m->forward_info->is_imported) {
@ -34697,7 +34695,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
if (dialog_type == DialogType::Channel && !message->contains_unread_mention) { if (dialog_type == DialogType::Channel && !message->contains_unread_mention) {
auto channel_read_media_period = auto channel_read_media_period =
G()->shared_config().get_option_integer("channels_read_media_period", (G()->is_test_dc() ? 300 : 7 * 86400)); G()->get_option_integer("channels_read_media_period", (G()->is_test_dc() ? 300 : 7 * 86400));
if (message->date < G()->unix_time_cached() - channel_read_media_period) { if (message->date < G()->unix_time_cached() - channel_read_media_period) {
update_opened_message_content(message->content.get()); update_opened_message_content(message->content.get());
} }

View File

@ -9,7 +9,6 @@
#include "td/telegram/AuthManager.h" #include "td/telegram/AuthManager.h"
#include "td/telegram/ChannelId.h" #include "td/telegram/ChannelId.h"
#include "td/telegram/ChatId.h" #include "td/telegram/ChatId.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ContactsManager.h" #include "td/telegram/ContactsManager.h"
#include "td/telegram/DeviceTokenManager.h" #include "td/telegram/DeviceTokenManager.h"
#include "td/telegram/Document.h" #include "td/telegram/Document.h"
@ -204,8 +203,7 @@ void NotificationManager::init() {
return; return;
} }
disable_contact_registered_notifications_ = disable_contact_registered_notifications_ = G()->get_option_boolean("disable_contact_registered_notifications");
G()->shared_config().get_option_boolean("disable_contact_registered_notifications");
auto sync_state = G()->td_db()->get_binlog_pmc()->get(get_is_contact_registered_notifications_synchronized_key()); auto sync_state = G()->td_db()->get_binlog_pmc()->get(get_is_contact_registered_notifications_synchronized_key());
if (sync_state.empty()) { if (sync_state.empty()) {
sync_state = "00"; sync_state = "00";
@ -2389,8 +2387,8 @@ void NotificationManager::on_notification_group_count_max_changed(bool send_upda
return; return;
} }
auto new_max_notification_group_count = narrow_cast<int32>( auto new_max_notification_group_count =
G()->shared_config().get_option_integer("notification_group_count_max", DEFAULT_GROUP_COUNT_MAX)); narrow_cast<int32>(G()->get_option_integer("notification_group_count_max", DEFAULT_GROUP_COUNT_MAX));
CHECK(MIN_NOTIFICATION_GROUP_COUNT_MAX <= new_max_notification_group_count && CHECK(MIN_NOTIFICATION_GROUP_COUNT_MAX <= new_max_notification_group_count &&
new_max_notification_group_count <= MAX_NOTIFICATION_GROUP_COUNT_MAX); new_max_notification_group_count <= MAX_NOTIFICATION_GROUP_COUNT_MAX);
@ -2453,8 +2451,8 @@ void NotificationManager::on_notification_group_size_max_changed() {
return; return;
} }
auto new_max_notification_group_size = narrow_cast<int32>( auto new_max_notification_group_size =
G()->shared_config().get_option_integer("notification_group_size_max", DEFAULT_GROUP_SIZE_MAX)); narrow_cast<int32>(G()->get_option_integer("notification_group_size_max", DEFAULT_GROUP_SIZE_MAX));
CHECK(MIN_NOTIFICATION_GROUP_SIZE_MAX <= new_max_notification_group_size && CHECK(MIN_NOTIFICATION_GROUP_SIZE_MAX <= new_max_notification_group_size &&
new_max_notification_group_size <= MAX_NOTIFICATION_GROUP_SIZE_MAX); new_max_notification_group_size <= MAX_NOTIFICATION_GROUP_SIZE_MAX);
@ -2536,8 +2534,8 @@ void NotificationManager::on_online_cloud_timeout_changed() {
return; return;
} }
online_cloud_timeout_ms_ = narrow_cast<int32>( online_cloud_timeout_ms_ =
G()->shared_config().get_option_integer("online_cloud_timeout_ms", DEFAULT_ONLINE_CLOUD_TIMEOUT_MS)); narrow_cast<int32>(G()->get_option_integer("online_cloud_timeout_ms", DEFAULT_ONLINE_CLOUD_TIMEOUT_MS));
VLOG(notifications) << "Set online_cloud_timeout_ms to " << online_cloud_timeout_ms_; VLOG(notifications) << "Set online_cloud_timeout_ms to " << online_cloud_timeout_ms_;
} }
@ -2546,8 +2544,8 @@ void NotificationManager::on_notification_cloud_delay_changed() {
return; return;
} }
notification_cloud_delay_ms_ = narrow_cast<int32>( notification_cloud_delay_ms_ =
G()->shared_config().get_option_integer("notification_cloud_delay_ms", DEFAULT_ONLINE_CLOUD_DELAY_MS)); narrow_cast<int32>(G()->get_option_integer("notification_cloud_delay_ms", DEFAULT_ONLINE_CLOUD_DELAY_MS));
VLOG(notifications) << "Set notification_cloud_delay_ms to " << notification_cloud_delay_ms_; VLOG(notifications) << "Set notification_cloud_delay_ms to " << notification_cloud_delay_ms_;
} }
@ -2556,8 +2554,8 @@ void NotificationManager::on_notification_default_delay_changed() {
return; return;
} }
notification_default_delay_ms_ = narrow_cast<int32>( notification_default_delay_ms_ =
G()->shared_config().get_option_integer("notification_default_delay_ms", DEFAULT_DEFAULT_DELAY_MS)); narrow_cast<int32>(G()->get_option_integer("notification_default_delay_ms", DEFAULT_DEFAULT_DELAY_MS));
VLOG(notifications) << "Set notification_default_delay_ms to " << notification_default_delay_ms_; VLOG(notifications) << "Set notification_default_delay_ms to " << notification_default_delay_ms_;
} }
@ -2566,7 +2564,7 @@ void NotificationManager::on_disable_contact_registered_notifications_changed()
return; return;
} }
auto is_disabled = G()->shared_config().get_option_boolean("disable_contact_registered_notifications"); auto is_disabled = G()->get_option_boolean("disable_contact_registered_notifications");
if (is_disabled == disable_contact_registered_notifications_) { if (is_disabled == disable_contact_registered_notifications_) {
return; return;
@ -2585,9 +2583,9 @@ void NotificationManager::on_get_disable_contact_registered_notifications(bool i
disable_contact_registered_notifications_ = is_disabled; disable_contact_registered_notifications_ = is_disabled;
if (is_disabled) { if (is_disabled) {
G()->shared_config().set_option_boolean("disable_contact_registered_notifications", is_disabled); G()->set_option_boolean("disable_contact_registered_notifications", is_disabled);
} else { } else {
G()->shared_config().set_option_empty("disable_contact_registered_notifications"); G()->set_option_empty("disable_contact_registered_notifications");
} }
} }

View File

@ -10,7 +10,6 @@
#include "td/telegram/AudiosManager.h" #include "td/telegram/AudiosManager.h"
#include "td/telegram/AudiosManager.hpp" #include "td/telegram/AudiosManager.hpp"
#include "td/telegram/AuthManager.h" #include "td/telegram/AuthManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ContactsManager.h" #include "td/telegram/ContactsManager.h"
#include "td/telegram/Document.h" #include "td/telegram/Document.h"
#include "td/telegram/DocumentsManager.h" #include "td/telegram/DocumentsManager.h"
@ -874,7 +873,7 @@ void NotificationSettingsManager::add_saved_ringtone(td_api::object_ptr<td_api::
FileId file_id = r_file_id.ok(); FileId file_id = r_file_id.ok();
auto file_view = td_->file_manager_->get_file_view(file_id); auto file_view = td_->file_manager_->get_file_view(file_id);
CHECK(!file_view.empty()); CHECK(!file_view.empty());
if (file_view.size() > G()->shared_config().get_option_integer("notification_sound_size_max")) { if (file_view.size() > G()->get_option_integer("notification_sound_size_max")) {
return promise.set_error(Status::Error(400, "Notification sound file is too big")); return promise.set_error(Status::Error(400, "Notification sound file is too big"));
} }
auto file_type = file_view.get_type(); auto file_type = file_view.get_type();
@ -889,7 +888,7 @@ void NotificationSettingsManager::add_saved_ringtone(td_api::object_ptr<td_api::
default: default:
break; break;
} }
if (duration > G()->shared_config().get_option_integer("notification_sound_duration_max")) { if (duration > G()->get_option_integer("notification_sound_duration_max")) {
return promise.set_error(Status::Error(400, "Notification sound is too long")); return promise.set_error(Status::Error(400, "Notification sound is too long"));
} }
if (file_view.has_remote_location() && !file_view.is_encrypted()) { if (file_view.has_remote_location() && !file_view.is_encrypted()) {
@ -1114,7 +1113,7 @@ void NotificationSettingsManager::on_remove_saved_ringtone(int64 ringtone_id, Pr
CHECK(are_saved_ringtones_loaded_); CHECK(are_saved_ringtones_loaded_);
auto max_count = G()->shared_config().get_option_integer("notification_sound_count_max"); auto max_count = G()->get_option_integer("notification_sound_count_max");
if (saved_ringtone_file_ids_.size() >= static_cast<uint64>(max_count)) { if (saved_ringtone_file_ids_.size() >= static_cast<uint64>(max_count)) {
// reload all saved ringtones to get ringtones besides the limit // reload all saved ringtones to get ringtones besides the limit
return reload_saved_ringtones(PromiseCreator::lambda([promise = std::move(promise)](Result<Unit> &&result) mutable { return reload_saved_ringtones(PromiseCreator::lambda([promise = std::move(promise)](Result<Unit> &&result) mutable {

View File

@ -10,7 +10,6 @@
#include "td/telegram/AttachMenuManager.h" #include "td/telegram/AttachMenuManager.h"
#include "td/telegram/AuthManager.h" #include "td/telegram/AuthManager.h"
#include "td/telegram/ConfigManager.h" #include "td/telegram/ConfigManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ContactsManager.h" #include "td/telegram/ContactsManager.h"
#include "td/telegram/DialogId.h" #include "td/telegram/DialogId.h"
#include "td/telegram/GitCommitHash.h" #include "td/telegram/GitCommitHash.h"
@ -44,54 +43,52 @@ namespace td {
OptionManager::OptionManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) { OptionManager::OptionManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
send_unix_time_update(); send_unix_time_update();
if (G()->shared_config().have_option("language_database_path")) { if (G()->have_option("language_database_path")) {
G()->shared_config().set_option_string("language_pack_database_path", G()->set_option_string("language_pack_database_path", G()->get_option_string("language_database_path"));
G()->shared_config().get_option_string("language_database_path")); G()->set_option_empty("language_database_path");
G()->shared_config().set_option_empty("language_database_path");
} }
if (G()->shared_config().have_option("language_pack")) { if (G()->have_option("language_pack")) {
G()->shared_config().set_option_string("localization_target", G()->set_option_string("localization_target", G()->get_option_string("language_pack"));
G()->shared_config().get_option_string("language_pack")); G()->set_option_empty("language_pack");
G()->shared_config().set_option_empty("language_pack");
} }
if (G()->shared_config().have_option("language_code")) { if (G()->have_option("language_code")) {
G()->shared_config().set_option_string("language_pack_id", G()->shared_config().get_option_string("language_code")); G()->set_option_string("language_pack_id", G()->get_option_string("language_code"));
G()->shared_config().set_option_empty("language_code"); G()->set_option_empty("language_code");
} }
if (!G()->shared_config().have_option("message_text_length_max")) { if (!G()->have_option("message_text_length_max")) {
G()->shared_config().set_option_integer("message_text_length_max", 4096); G()->set_option_integer("message_text_length_max", 4096);
} }
if (!G()->shared_config().have_option("message_caption_length_max")) { if (!G()->have_option("message_caption_length_max")) {
G()->shared_config().set_option_integer("message_caption_length_max", 1024); G()->set_option_integer("message_caption_length_max", 1024);
} }
if (!G()->shared_config().have_option("bio_length_max")) { if (!G()->have_option("bio_length_max")) {
G()->shared_config().set_option_integer("bio_length_max", 70); G()->set_option_integer("bio_length_max", 70);
} }
if (!G()->shared_config().have_option("suggested_video_note_length")) { if (!G()->have_option("suggested_video_note_length")) {
G()->shared_config().set_option_integer("suggested_video_note_length", 384); G()->set_option_integer("suggested_video_note_length", 384);
} }
if (!G()->shared_config().have_option("suggested_video_note_video_bitrate")) { if (!G()->have_option("suggested_video_note_video_bitrate")) {
G()->shared_config().set_option_integer("suggested_video_note_video_bitrate", 1000); G()->set_option_integer("suggested_video_note_video_bitrate", 1000);
} }
if (!G()->shared_config().have_option("suggested_video_note_audio_bitrate")) { if (!G()->have_option("suggested_video_note_audio_bitrate")) {
G()->shared_config().set_option_integer("suggested_video_note_audio_bitrate", 64); G()->set_option_integer("suggested_video_note_audio_bitrate", 64);
} }
if (!G()->shared_config().have_option("notification_sound_duration_max")) { if (!G()->have_option("notification_sound_duration_max")) {
G()->shared_config().set_option_integer("notification_sound_duration_max", 5); G()->set_option_integer("notification_sound_duration_max", 5);
} }
if (!G()->shared_config().have_option("notification_sound_size_max")) { if (!G()->have_option("notification_sound_size_max")) {
G()->shared_config().set_option_integer("notification_sound_size_max", 307200); G()->set_option_integer("notification_sound_size_max", 307200);
} }
if (!G()->shared_config().have_option("notification_sound_count_max")) { if (!G()->have_option("notification_sound_count_max")) {
G()->shared_config().set_option_integer("notification_sound_count_max", G()->is_test_dc() ? 5 : 100); G()->set_option_integer("notification_sound_count_max", G()->is_test_dc() ? 5 : 100);
} }
if (!G()->shared_config().have_option("chat_filter_count_max")) { if (!G()->have_option("chat_filter_count_max")) {
G()->shared_config().set_option_integer("chat_filter_count_max", G()->is_test_dc() ? 3 : 10); G()->set_option_integer("chat_filter_count_max", G()->is_test_dc() ? 3 : 10);
} }
if (!G()->shared_config().have_option("chat_filter_chosen_chat_count_max")) { if (!G()->have_option("chat_filter_chosen_chat_count_max")) {
G()->shared_config().set_option_integer("chat_filter_chosen_chat_count_max", G()->is_test_dc() ? 5 : 100); G()->set_option_integer("chat_filter_chosen_chat_count_max", G()->is_test_dc() ? 5 : 100);
} }
G()->shared_config().set_option_integer("utc_time_offset", Clocks::tz_offset()); G()->set_option_integer("utc_time_offset", Clocks::tz_offset());
} }
void OptionManager::tear_down() { void OptionManager::tear_down() {
@ -118,7 +115,7 @@ void OptionManager::on_update_server_time_difference() {
} }
void OptionManager::clear_options() { void OptionManager::clear_options() {
for (const auto &option : G()->shared_config().get_options()) { for (const auto &option : G()->get_options()) {
if (!is_internal_option(option.first)) { if (!is_internal_option(option.first)) {
send_closure( send_closure(
G()->td(), &Td::send_update, G()->td(), &Td::send_update,
@ -199,14 +196,13 @@ void OptionManager::on_option_updated(const string &name) {
// nothing to do: animated emoji zoom is updated only at launch // nothing to do: animated emoji zoom is updated only at launch
} }
if (name == "animation_search_emojis") { if (name == "animation_search_emojis") {
td_->animations_manager_->on_update_animation_search_emojis(G()->shared_config().get_option_string(name)); td_->animations_manager_->on_update_animation_search_emojis(G()->get_option_string(name));
} }
if (name == "animation_search_provider") { if (name == "animation_search_provider") {
td_->animations_manager_->on_update_animation_search_provider(G()->shared_config().get_option_string(name)); td_->animations_manager_->on_update_animation_search_provider(G()->get_option_string(name));
} }
if (name == "auth") { if (name == "auth") {
send_closure(td_->auth_manager_actor_, &AuthManager::on_authorization_lost, send_closure(td_->auth_manager_actor_, &AuthManager::on_authorization_lost, G()->get_option_string(name));
G()->shared_config().get_option_string(name));
} }
break; break;
case 'b': case 'b':
@ -216,13 +212,13 @@ void OptionManager::on_option_updated(const string &name) {
break; break;
case 'c': case 'c':
if (name == "connection_parameters") { if (name == "connection_parameters") {
if (G()->mtproto_header().set_parameters(G()->shared_config().get_option_string(name))) { if (G()->mtproto_header().set_parameters(G()->get_option_string(name))) {
G()->net_query_dispatcher().update_mtproto_header(); G()->net_query_dispatcher().update_mtproto_header();
} }
} }
break; break;
case 'd': case 'd':
if (name == "default_reaction_needs_sync" && G()->shared_config().get_option_boolean(name)) { if (name == "default_reaction_needs_sync" && G()->get_option_boolean(name)) {
send_set_default_reaction_query(td_); send_set_default_reaction_query(td_);
} }
if (name == "dice_emojis") { if (name == "dice_emojis") {
@ -240,7 +236,7 @@ void OptionManager::on_option_updated(const string &name) {
} }
if (name == "disable_top_chats") { if (name == "disable_top_chats") {
send_closure(td_->top_dialog_manager_actor_, &TopDialogManager::update_is_enabled, send_closure(td_->top_dialog_manager_actor_, &TopDialogManager::update_is_enabled,
!G()->shared_config().get_option_boolean(name)); !G()->get_option_boolean(name));
} }
break; break;
case 'e': case 'e':
@ -250,8 +246,7 @@ void OptionManager::on_option_updated(const string &name) {
break; break;
case 'f': case 'f':
if (name == "favorite_stickers_limit") { if (name == "favorite_stickers_limit") {
td_->stickers_manager_->on_update_favorite_stickers_limit( td_->stickers_manager_->on_update_favorite_stickers_limit(narrow_cast<int32>(G()->get_option_integer(name)));
narrow_cast<int32>(G()->shared_config().get_option_integer(name)));
} }
break; break;
case 'i': case 'i':
@ -259,7 +254,7 @@ void OptionManager::on_option_updated(const string &name) {
send_closure(td_->contacts_manager_actor_, &ContactsManager::on_ignored_restriction_reasons_changed); send_closure(td_->contacts_manager_actor_, &ContactsManager::on_ignored_restriction_reasons_changed);
} }
if (name == "is_emulator") { if (name == "is_emulator") {
if (G()->mtproto_header().set_is_emulator(G()->shared_config().get_option_boolean(name))) { if (G()->mtproto_header().set_is_emulator(G()->get_option_boolean(name))) {
G()->net_query_dispatcher().update_mtproto_header(); G()->net_query_dispatcher().update_mtproto_header();
} }
} }
@ -267,7 +262,7 @@ void OptionManager::on_option_updated(const string &name) {
case 'l': case 'l':
if (name == "language_pack_id") { if (name == "language_pack_id") {
send_closure(td_->language_pack_manager_, &LanguagePackManager::on_language_code_changed); send_closure(td_->language_pack_manager_, &LanguagePackManager::on_language_code_changed);
if (G()->mtproto_header().set_language_code(G()->shared_config().get_option_string(name))) { if (G()->mtproto_header().set_language_code(G()->get_option_string(name))) {
G()->net_query_dispatcher().update_mtproto_header(); G()->net_query_dispatcher().update_mtproto_header();
} }
send_closure(td_->attach_menu_manager_actor_, &AttachMenuManager::reload_attach_menu_bots, Promise<Unit>()); send_closure(td_->attach_menu_manager_actor_, &AttachMenuManager::reload_attach_menu_bots, Promise<Unit>());
@ -277,14 +272,14 @@ void OptionManager::on_option_updated(const string &name) {
} }
if (name == "localization_target") { if (name == "localization_target") {
send_closure(td_->language_pack_manager_, &LanguagePackManager::on_language_pack_changed); send_closure(td_->language_pack_manager_, &LanguagePackManager::on_language_pack_changed);
if (G()->mtproto_header().set_language_pack(G()->shared_config().get_option_string(name))) { if (G()->mtproto_header().set_language_pack(G()->get_option_string(name))) {
G()->net_query_dispatcher().update_mtproto_header(); G()->net_query_dispatcher().update_mtproto_header();
} }
} }
break; break;
case 'm': case 'm':
if (name == "my_id") { if (name == "my_id") {
G()->set_my_id(G()->shared_config().get_option_integer(name)); G()->set_my_id(G()->get_option_integer(name));
} }
break; break;
case 'n': case 'n':
@ -307,7 +302,7 @@ void OptionManager::on_option_updated(const string &name) {
send_closure(td_->notification_manager_actor_, &NotificationManager::on_online_cloud_timeout_changed); send_closure(td_->notification_manager_actor_, &NotificationManager::on_online_cloud_timeout_changed);
} }
if (name == "otherwise_relogin_days") { if (name == "otherwise_relogin_days") {
auto days = narrow_cast<int32>(G()->shared_config().get_option_integer(name)); auto days = narrow_cast<int32>(G()->get_option_integer(name));
if (days > 0) { if (days > 0) {
vector<SuggestedAction> added_actions{SuggestedAction{SuggestedAction::Type::SetPassword, DialogId(), days}}; vector<SuggestedAction> added_actions{SuggestedAction{SuggestedAction::Type::SetPassword, DialogId(), days}};
send_closure(G()->td(), &Td::send_update, get_update_suggested_actions_object(added_actions, {})); send_closure(G()->td(), &Td::send_update, get_update_suggested_actions_object(added_actions, {}));
@ -319,14 +314,12 @@ void OptionManager::on_option_updated(const string &name) {
send_closure(td_->top_dialog_manager_actor_, &TopDialogManager::update_rating_e_decay); send_closure(td_->top_dialog_manager_actor_, &TopDialogManager::update_rating_e_decay);
} }
if (name == "recent_stickers_limit") { if (name == "recent_stickers_limit") {
td_->stickers_manager_->on_update_recent_stickers_limit( td_->stickers_manager_->on_update_recent_stickers_limit(narrow_cast<int32>(G()->get_option_integer(name)));
narrow_cast<int32>(G()->shared_config().get_option_integer(name)));
} }
break; break;
case 's': case 's':
if (name == "saved_animations_limit") { if (name == "saved_animations_limit") {
td_->animations_manager_->on_update_saved_animations_limit( td_->animations_manager_->on_update_saved_animations_limit(narrow_cast<int32>(G()->get_option_integer(name)));
narrow_cast<int32>(G()->shared_config().get_option_integer(name)));
} }
if (name == "session_count") { if (name == "session_count") {
G()->net_query_dispatcher().update_session_count(); G()->net_query_dispatcher().update_session_count();
@ -340,7 +333,7 @@ void OptionManager::on_option_updated(const string &name) {
send_closure(td_->storage_manager_, &StorageManager::update_use_storage_optimizer); send_closure(td_->storage_manager_, &StorageManager::update_use_storage_optimizer);
} }
if (name == "utc_time_offset") { if (name == "utc_time_offset") {
if (G()->mtproto_header().set_tz_offset(static_cast<int32>(G()->shared_config().get_option_integer(name)))) { if (G()->mtproto_header().set_tz_offset(static_cast<int32>(G()->get_option_integer(name)))) {
G()->net_query_dispatcher().update_mtproto_header(); G()->net_query_dispatcher().update_mtproto_header();
} }
} }
@ -354,8 +347,7 @@ void OptionManager::on_option_updated(const string &name) {
} }
// send_closure was already used in the callback // send_closure was already used in the callback
td_->send_update( td_->send_update(td_api::make_object<td_api::updateOption>(name, get_option_value_object(G()->get_option(name))));
td_api::make_object<td_api::updateOption>(name, get_option_value_object(G()->shared_config().get_option(name))));
} }
void OptionManager::get_option(const string &name, Promise<td_api::object_ptr<td_api::OptionValue>> &&promise) { void OptionManager::get_option(const string &name, Promise<td_api::object_ptr<td_api::OptionValue>> &&promise) {
@ -363,7 +355,7 @@ void OptionManager::get_option(const string &name, Promise<td_api::object_ptr<td
auto wrap_promise = [&] { auto wrap_promise = [&] {
return PromiseCreator::lambda([promise = std::move(promise), name](Unit result) mutable { return PromiseCreator::lambda([promise = std::move(promise), name](Unit result) mutable {
// the option is already updated on success, ignore errors // the option is already updated on success, ignore errors
promise.set_value(get_option_value_object(G()->shared_config().get_option(name))); promise.set_value(get_option_value_object(G()->get_option(name)));
}); });
}; };
switch (name[0]) { switch (name[0]) {
@ -434,7 +426,7 @@ void OptionManager::set_option(const string &name, td_api::object_ptr<td_api::Op
return false; return false;
} }
if (value_constructor_id == td_api::optionValueEmpty::ID) { if (value_constructor_id == td_api::optionValueEmpty::ID) {
G()->shared_config().set_option_empty(option_name); G()->set_option_empty(option_name);
} else { } else {
if (value_constructor_id != td_api::optionValueInteger::ID) { if (value_constructor_id != td_api::optionValueInteger::ID) {
promise.set_error(Status::Error(400, PSLICE() << "Option \"" << name << "\" must have integer value")); promise.set_error(Status::Error(400, PSLICE() << "Option \"" << name << "\" must have integer value"));
@ -448,7 +440,7 @@ void OptionManager::set_option(const string &name, td_api::object_ptr<td_api::Op
<< max_value << "]")); << max_value << "]"));
return false; return false;
} }
G()->shared_config().set_option_integer(name, int_value); G()->set_option_integer(name, int_value);
} }
promise.set_value(Unit()); promise.set_value(Unit());
return true; return true;
@ -459,7 +451,7 @@ void OptionManager::set_option(const string &name, td_api::object_ptr<td_api::Op
return false; return false;
} }
if (value_constructor_id == td_api::optionValueEmpty::ID) { if (value_constructor_id == td_api::optionValueEmpty::ID) {
G()->shared_config().set_option_empty(name); G()->set_option_empty(name);
} else { } else {
if (value_constructor_id != td_api::optionValueBoolean::ID) { if (value_constructor_id != td_api::optionValueBoolean::ID) {
promise.set_error(Status::Error(400, PSLICE() << "Option \"" << name << "\" must have boolean value")); promise.set_error(Status::Error(400, PSLICE() << "Option \"" << name << "\" must have boolean value"));
@ -467,7 +459,7 @@ void OptionManager::set_option(const string &name, td_api::object_ptr<td_api::Op
} }
bool bool_value = static_cast<td_api::optionValueBoolean *>(value.get())->value_; bool bool_value = static_cast<td_api::optionValueBoolean *>(value.get())->value_;
G()->shared_config().set_option_boolean(name, bool_value); G()->set_option_boolean(name, bool_value);
} }
promise.set_value(Unit()); promise.set_value(Unit());
return true; return true;
@ -478,7 +470,7 @@ void OptionManager::set_option(const string &name, td_api::object_ptr<td_api::Op
return false; return false;
} }
if (value_constructor_id == td_api::optionValueEmpty::ID) { if (value_constructor_id == td_api::optionValueEmpty::ID) {
G()->shared_config().set_option_empty(name); G()->set_option_empty(name);
} else { } else {
if (value_constructor_id != td_api::optionValueString::ID) { if (value_constructor_id != td_api::optionValueString::ID) {
promise.set_error(Status::Error(400, PSLICE() << "Option \"" << name << "\" must have string value")); promise.set_error(Status::Error(400, PSLICE() << "Option \"" << name << "\" must have string value"));
@ -487,10 +479,10 @@ void OptionManager::set_option(const string &name, td_api::object_ptr<td_api::Op
const string &str_value = static_cast<td_api::optionValueString *>(value.get())->value_; const string &str_value = static_cast<td_api::optionValueString *>(value.get())->value_;
if (str_value.empty()) { if (str_value.empty()) {
G()->shared_config().set_option_empty(name); G()->set_option_empty(name);
} else { } else {
if (check_value(str_value)) { if (check_value(str_value)) {
G()->shared_config().set_option_string(name, str_value); G()->set_option_string(name, str_value);
} else { } else {
promise.set_error(Status::Error(400, PSLICE() << "Option \"" << name << "\" can't have specified value")); promise.set_error(Status::Error(400, PSLICE() << "Option \"" << name << "\" can't have specified value"));
return false; return false;
@ -583,7 +575,7 @@ void OptionManager::set_option(const string &name, td_api::object_ptr<td_api::Op
return; return;
} }
if (!is_bot && name == "ignore_sensitive_content_restrictions") { if (!is_bot && name == "ignore_sensitive_content_restrictions") {
if (!G()->shared_config().get_option_boolean("can_ignore_sensitive_content_restrictions")) { if (!G()->get_option_boolean("can_ignore_sensitive_content_restrictions")) {
return promise.set_error( return promise.set_error(
Status::Error(400, "Option \"ignore_sensitive_content_restrictions\" can't be changed by the user")); Status::Error(400, "Option \"ignore_sensitive_content_restrictions\" can't be changed by the user"));
} }
@ -703,19 +695,16 @@ void OptionManager::set_option(const string &name, td_api::object_ptr<td_api::Op
} }
switch (value_constructor_id) { switch (value_constructor_id) {
case td_api::optionValueBoolean::ID: case td_api::optionValueBoolean::ID:
G()->shared_config().set_option_boolean(name, G()->set_option_boolean(name, static_cast<const td_api::optionValueBoolean *>(value.get())->value_);
static_cast<const td_api::optionValueBoolean *>(value.get())->value_);
break; break;
case td_api::optionValueEmpty::ID: case td_api::optionValueEmpty::ID:
G()->shared_config().set_option_empty(name); G()->set_option_empty(name);
break; break;
case td_api::optionValueInteger::ID: case td_api::optionValueInteger::ID:
G()->shared_config().set_option_integer(name, G()->set_option_integer(name, static_cast<const td_api::optionValueInteger *>(value.get())->value_);
static_cast<const td_api::optionValueInteger *>(value.get())->value_);
break; break;
case td_api::optionValueString::ID: case td_api::optionValueString::ID:
G()->shared_config().set_option_string(name, G()->set_option_string(name, static_cast<const td_api::optionValueString *>(value.get())->value_);
static_cast<const td_api::optionValueString *>(value.get())->value_);
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
@ -767,7 +756,7 @@ void OptionManager::get_current_state(vector<td_api::object_ptr<td_api::Update>>
updates.push_back(td_api::make_object<td_api::updateOption>("unix_time", get_unix_time_option_value_object())); updates.push_back(td_api::make_object<td_api::updateOption>("unix_time", get_unix_time_option_value_object()));
for (const auto &option : G()->shared_config().get_options()) { for (const auto &option : G()->get_options()) {
if (!is_internal_option(option.first)) { if (!is_internal_option(option.first)) {
updates.push_back( updates.push_back(
td_api::make_object<td_api::updateOption>(option.first, get_option_value_object(option.second))); td_api::make_object<td_api::updateOption>(option.first, get_option_value_object(option.second)));

View File

@ -7,7 +7,6 @@
#include "td/telegram/PasswordManager.h" #include "td/telegram/PasswordManager.h"
#include "td/telegram/ConfigManager.h" #include "td/telegram/ConfigManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/DhCache.h" #include "td/telegram/DhCache.h"
#include "td/telegram/DialogId.h" #include "td/telegram/DialogId.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
@ -785,7 +784,7 @@ void PasswordManager::do_get_state(Promise<PasswordState> promise) {
state.has_recovery_email_address = password->has_recovery_; state.has_recovery_email_address = password->has_recovery_;
state.has_secure_values = password->has_secure_values_; state.has_secure_values = password->has_secure_values_;
auto days = narrow_cast<int32>(G()->shared_config().get_option_integer("otherwise_relogin_days")); auto days = narrow_cast<int32>(G()->get_option_integer("otherwise_relogin_days"));
if (days > 0) { if (days > 0) {
dismiss_suggested_action(SuggestedAction{SuggestedAction::Type::SetPassword, DialogId(), days}, dismiss_suggested_action(SuggestedAction{SuggestedAction::Type::SetPassword, DialogId(), days},
Promise<Unit>()); Promise<Unit>());

View File

@ -8,7 +8,6 @@
#include "td/telegram/AnimationsManager.h" #include "td/telegram/AnimationsManager.h"
#include "td/telegram/Application.h" #include "td/telegram/Application.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ContactsManager.h" #include "td/telegram/ContactsManager.h"
#include "td/telegram/DialogId.h" #include "td/telegram/DialogId.h"
#include "td/telegram/Document.h" #include "td/telegram/Document.h"
@ -398,10 +397,8 @@ static string get_premium_source(const td_api::object_ptr<td_api::PremiumSource>
} }
static td_api::object_ptr<td_api::premiumLimit> get_premium_limit_object(Slice key) { static td_api::object_ptr<td_api::premiumLimit> get_premium_limit_object(Slice key) {
int32 default_limit = int32 default_limit = static_cast<int32>(G()->get_option_integer(PSLICE() << key << "_limit_default"));
static_cast<int32>(G()->shared_config().get_option_integer(PSLICE() << key << "_limit_default")); int32 premium_limit = static_cast<int32>(G()->get_option_integer(PSLICE() << key << "_limit_premium"));
int32 premium_limit =
static_cast<int32>(G()->shared_config().get_option_integer(PSLICE() << key << "_limit_premium"));
if (default_limit <= 0 || premium_limit <= default_limit) { if (default_limit <= 0 || premium_limit <= default_limit) {
return nullptr; return nullptr;
} }
@ -454,7 +451,7 @@ void get_premium_limit(const td_api::object_ptr<td_api::PremiumLimitType> &limit
void get_premium_features(Td *td, const td_api::object_ptr<td_api::PremiumSource> &source, void get_premium_features(Td *td, const td_api::object_ptr<td_api::PremiumSource> &source,
Promise<td_api::object_ptr<td_api::premiumFeatures>> &&promise) { Promise<td_api::object_ptr<td_api::premiumFeatures>> &&promise) {
auto premium_features = auto premium_features =
full_split(G()->shared_config().get_option_string( full_split(G()->get_option_string(
"premium_features", "premium_features",
"double_limits,more_upload,faster_download,voice_to_text,no_ads,unique_reactions,premium_stickers," "double_limits,more_upload,faster_download,voice_to_text,no_ads,unique_reactions,premium_stickers,"
"animated_emoji,advanced_chat_management,profile_badge,animated_userpics,app_icons"), "animated_emoji,advanced_chat_management,profile_badge,animated_userpics,app_icons"),
@ -486,11 +483,11 @@ void get_premium_features(Td *td, const td_api::object_ptr<td_api::PremiumSource
} }
td_api::object_ptr<td_api::InternalLinkType> payment_link; td_api::object_ptr<td_api::InternalLinkType> payment_link;
auto premium_bot_username = G()->shared_config().get_option_string("premium_bot_username"); auto premium_bot_username = G()->get_option_string("premium_bot_username");
if (!premium_bot_username.empty()) { if (!premium_bot_username.empty()) {
payment_link = td_api::make_object<td_api::internalLinkTypeBotStart>(premium_bot_username, source_str, true); payment_link = td_api::make_object<td_api::internalLinkTypeBotStart>(premium_bot_username, source_str, true);
} else { } else {
auto premium_invoice_slug = G()->shared_config().get_option_string("premium_invoice_slug"); auto premium_invoice_slug = G()->get_option_string("premium_invoice_slug");
if (!premium_invoice_slug.empty()) { if (!premium_invoice_slug.empty()) {
payment_link = td_api::make_object<td_api::internalLinkTypeInvoice>(premium_invoice_slug); payment_link = td_api::make_object<td_api::internalLinkTypeInvoice>(premium_invoice_slug);
} }

View File

@ -6,7 +6,6 @@
// //
#include "td/telegram/RestrictionReason.h" #include "td/telegram/RestrictionReason.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
#include "td/utils/algorithm.h" #include "td/utils/algorithm.h"
@ -22,10 +21,9 @@ string get_restriction_reason_description(const vector<RestrictionReason> &restr
return string(); return string();
} }
auto ignored_restriction_reasons = auto ignored_restriction_reasons = full_split(G()->get_option_string("ignored_restriction_reasons"), ',');
full_split(G()->shared_config().get_option_string("ignored_restriction_reasons"), ',');
auto platform = [] { auto platform = [] {
if (G()->shared_config().get_option_boolean("ignore_platform_restrictions")) { if (G()->get_option_boolean("ignore_platform_restrictions")) {
return Slice(); return Slice();
} }

View File

@ -6,7 +6,6 @@
// //
#include "td/telegram/SecretChatsManager.h" #include "td/telegram/SecretChatsManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ContactsManager.h" #include "td/telegram/ContactsManager.h"
#include "td/telegram/DhCache.h" #include "td/telegram/DhCache.h"
#include "td/telegram/EncryptedFile.h" #include "td/telegram/EncryptedFile.h"
@ -321,7 +320,7 @@ unique_ptr<SecretChatActor::Context> SecretChatsManager::make_secret_chat_contex
} }
bool get_config_option_boolean(const string &name) const final { bool get_config_option_boolean(const string &name) const final {
return G()->shared_config().get_option_boolean(name); return G()->get_option_boolean(name);
} }
int32 unix_time() final { int32 unix_time() final {

View File

@ -7,7 +7,6 @@
#include "td/telegram/SponsoredMessageManager.h" #include "td/telegram/SponsoredMessageManager.h"
#include "td/telegram/ChannelId.h" #include "td/telegram/ChannelId.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ContactsManager.h" #include "td/telegram/ContactsManager.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
#include "td/telegram/LinkManager.h" #include "td/telegram/LinkManager.h"
@ -169,7 +168,7 @@ td_api::object_ptr<td_api::sponsoredMessage> SponsoredMessageManager::get_sponso
case DialogType::Channel: case DialogType::Channel:
if (sponsored_message.server_message_id.is_valid()) { if (sponsored_message.server_message_id.is_valid()) {
auto channel_id = sponsored_message.sponsor_dialog_id.get_channel_id(); auto channel_id = sponsored_message.sponsor_dialog_id.get_channel_id();
auto t_me = G()->shared_config().get_option_string("t_me_url", "https://t.me/"); auto t_me = G()->get_option_string("t_me_url", "https://t.me/");
link = td_api::make_object<td_api::internalLinkTypeMessage>( link = td_api::make_object<td_api::internalLinkTypeMessage>(
PSTRING() << t_me << "c/" << channel_id.get() << '/' << sponsored_message.server_message_id.get()); PSTRING() << t_me << "c/" << channel_id.get() << '/' << sponsored_message.server_message_id.get());
} }

View File

@ -10,7 +10,6 @@
#include "td/telegram/AuthManager.h" #include "td/telegram/AuthManager.h"
#include "td/telegram/AvailableReaction.h" #include "td/telegram/AvailableReaction.h"
#include "td/telegram/ConfigManager.h" #include "td/telegram/ConfigManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ContactsManager.h" #include "td/telegram/ContactsManager.h"
#include "td/telegram/DialogId.h" #include "td/telegram/DialogId.h"
#include "td/telegram/Document.h" #include "td/telegram/Document.h"
@ -1391,10 +1390,8 @@ StickersManager::StickersManager(Td *td, ActorShared<> parent) : td_(td), parent
on_update_animated_emoji_zoom(); on_update_animated_emoji_zoom();
on_update_recent_stickers_limit( on_update_recent_stickers_limit(narrow_cast<int32>(G()->get_option_integer("recent_stickers_limit", 200)));
narrow_cast<int32>(G()->shared_config().get_option_integer("recent_stickers_limit", 200))); on_update_favorite_stickers_limit(narrow_cast<int32>(G()->get_option_integer("favorite_stickers_limit", 5)));
on_update_favorite_stickers_limit(
narrow_cast<int32>(G()->shared_config().get_option_integer("favorite_stickers_limit", 5)));
next_click_animated_emoji_message_time_ = Time::now(); next_click_animated_emoji_message_time_ = Time::now();
next_update_animated_emoji_clicked_time_ = Time::now(); next_update_animated_emoji_clicked_time_ = Time::now();
@ -1438,8 +1435,7 @@ void StickersManager::init() {
auto &sticker_set = add_special_sticker_set(SpecialStickerSetType::premium_gifts()); auto &sticker_set = add_special_sticker_set(SpecialStickerSetType::premium_gifts());
load_special_sticker_set_info_from_binlog(sticker_set); load_special_sticker_set_info_from_binlog(sticker_set);
dice_emojis_str_ = dice_emojis_str_ = G()->get_option_string("dice_emojis", "🎲\x01🎯\x01🏀\x01\x01⚽️\x01🎰\x01🎳");
G()->shared_config().get_option_string("dice_emojis", "🎲\x01🎯\x01🏀\x01\x01⚽️\x01🎰\x01🎳");
dice_emojis_ = full_split(dice_emojis_str_, '\x01'); dice_emojis_ = full_split(dice_emojis_str_, '\x01');
for (auto &dice_emoji : dice_emojis_) { for (auto &dice_emoji : dice_emojis_) {
auto &animated_dice_sticker_set = add_special_sticker_set(SpecialStickerSetType::animated_dice(dice_emoji)); auto &animated_dice_sticker_set = add_special_sticker_set(SpecialStickerSetType::animated_dice(dice_emoji));
@ -1474,8 +1470,8 @@ void StickersManager::init() {
} }
G()->td_db()->get_binlog_pmc()->erase("animated_dice_sticker_set"); // legacy G()->td_db()->get_binlog_pmc()->erase("animated_dice_sticker_set"); // legacy
G()->shared_config().set_option_empty("animated_dice_sticker_set_name"); // legacy G()->set_option_empty("animated_dice_sticker_set_name"); // legacy
G()->shared_config().set_option_empty("animated_emoji_sticker_set_name"); // legacy G()->set_option_empty("animated_emoji_sticker_set_name"); // legacy
} }
void StickersManager::reload_reactions() { void StickersManager::reload_reactions() {
@ -2234,7 +2230,7 @@ tl_object_ptr<td_api::stickerSetInfo> StickersManager::get_sticker_set_info_obje
vector<FileId> regular_sticker_ids; vector<FileId> regular_sticker_ids;
vector<FileId> premium_sticker_ids; vector<FileId> premium_sticker_ids;
std::tie(regular_sticker_ids, premium_sticker_ids) = split_stickers_by_premium(sticker_set); std::tie(regular_sticker_ids, premium_sticker_ids) = split_stickers_by_premium(sticker_set);
auto is_premium = G()->shared_config().get_option_boolean("is_premium"); auto is_premium = G()->get_option_boolean("is_premium");
size_t max_premium_stickers = is_premium ? covers_limit : 1; size_t max_premium_stickers = is_premium ? covers_limit : 1;
if (premium_sticker_ids.size() > max_premium_stickers) { if (premium_sticker_ids.size() > max_premium_stickers) {
premium_sticker_ids.resize(max_premium_stickers); premium_sticker_ids.resize(max_premium_stickers);
@ -4114,8 +4110,8 @@ vector<FileId> StickersManager::get_stickers(StickerType sticker_type, string em
vector<FileId> regular_sticker_ids; vector<FileId> regular_sticker_ids;
vector<FileId> premium_sticker_ids; vector<FileId> premium_sticker_ids;
std::tie(regular_sticker_ids, premium_sticker_ids) = split_stickers_by_premium(result); std::tie(regular_sticker_ids, premium_sticker_ids) = split_stickers_by_premium(result);
if (G()->shared_config().get_option_boolean("is_premium") || allow_premium) { if (G()->get_option_boolean("is_premium") || allow_premium) {
auto normal_count = G()->shared_config().get_option_integer("stickers_normal_by_emoji_per_premium_num", 2); auto normal_count = G()->get_option_integer("stickers_normal_by_emoji_per_premium_num", 2);
if (normal_count < 0) { if (normal_count < 0) {
normal_count = 2; normal_count = 2;
} }
@ -4150,7 +4146,7 @@ vector<FileId> StickersManager::get_stickers(StickerType sticker_type, string em
} }
} }
if (sorted.size() < limit_size_t) { if (sorted.size() < limit_size_t) {
auto premium_count = G()->shared_config().get_option_integer("stickers_premium_by_emoji_num", 0); auto premium_count = G()->get_option_integer("stickers_premium_by_emoji_num", 0);
if (premium_count > 0) { if (premium_count > 0) {
for (const auto &sticker_id : premium_sticker_ids) { for (const auto &sticker_id : premium_sticker_ids) {
LOG(INFO) << "Add premium sticker " << sticker_id << " from installed sticker set"; LOG(INFO) << "Add premium sticker " << sticker_id << " from installed sticker set";
@ -5014,15 +5010,14 @@ void StickersManager::on_update_dice_emojis() {
return; return;
} }
if (td_->auth_manager_->is_bot()) { if (td_->auth_manager_->is_bot()) {
G()->shared_config().set_option_empty("dice_emojis"); G()->set_option_empty("dice_emojis");
return; return;
} }
if (!is_inited_) { if (!is_inited_) {
return; return;
} }
auto dice_emojis_str = auto dice_emojis_str = G()->get_option_string("dice_emojis", "🎲\x01🎯\x01🏀\x01\x01⚽️\x01🎰\x01🎳");
G()->shared_config().get_option_string("dice_emojis", "🎲\x01🎯\x01🏀\x01\x01⚽️\x01🎰\x01🎳");
if (dice_emojis_str == dice_emojis_str_) { if (dice_emojis_str == dice_emojis_str_) {
return; return;
} }
@ -5054,15 +5049,14 @@ void StickersManager::on_update_dice_success_values() {
return; return;
} }
if (td_->auth_manager_->is_bot()) { if (td_->auth_manager_->is_bot()) {
G()->shared_config().set_option_empty("dice_success_values"); G()->set_option_empty("dice_success_values");
return; return;
} }
if (!is_inited_) { if (!is_inited_) {
return; return;
} }
auto dice_success_values_str = auto dice_success_values_str = G()->get_option_string("dice_success_values", "0,6:62,5:110,5:110,5:110,64:110,6:110");
G()->shared_config().get_option_string("dice_success_values", "0,6:62,5:110,5:110,5:110,64:110,6:110");
if (dice_success_values_str == dice_success_values_str_) { if (dice_success_values_str == dice_success_values_str_) {
return; return;
} }
@ -5080,7 +5074,7 @@ void StickersManager::on_update_emoji_sounds() {
return; return;
} }
auto emoji_sounds_str = G()->shared_config().get_option_string("emoji_sounds"); auto emoji_sounds_str = G()->get_option_string("emoji_sounds");
if (emoji_sounds_str == emoji_sounds_str_) { if (emoji_sounds_str == emoji_sounds_str_) {
return; return;
} }
@ -5127,7 +5121,7 @@ void StickersManager::on_update_disable_animated_emojis() {
return; return;
} }
auto disable_animated_emojis = G()->shared_config().get_option_boolean("disable_animated_emoji"); auto disable_animated_emojis = G()->get_option_boolean("disable_animated_emoji");
if (disable_animated_emojis == disable_animated_emojis_) { if (disable_animated_emojis == disable_animated_emojis_) {
return; return;
} }
@ -7908,8 +7902,7 @@ void StickersManager::save_recent_stickers_to_database(bool is_attached) {
} }
void StickersManager::on_update_animated_emoji_zoom() { void StickersManager::on_update_animated_emoji_zoom() {
animated_emoji_zoom_ = animated_emoji_zoom_ = static_cast<double>(G()->get_option_integer("animated_emoji_zoom", 625000000)) * 1e-9;
static_cast<double>(G()->shared_config().get_option_integer("animated_emoji_zoom", 625000000)) * 1e-9;
} }
void StickersManager::on_update_recent_stickers_limit(int32 recent_stickers_limit) { void StickersManager::on_update_recent_stickers_limit(int32 recent_stickers_limit) {

View File

@ -6,7 +6,6 @@
// //
#include "td/telegram/StorageManager.h" #include "td/telegram/StorageManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/DialogId.h" #include "td/telegram/DialogId.h"
#include "td/telegram/files/FileGcWorker.h" #include "td/telegram/files/FileGcWorker.h"
#include "td/telegram/files/FileStatsWorker.h" #include "td/telegram/files/FileStatsWorker.h"
@ -188,7 +187,7 @@ int64 StorageManager::get_database_size() {
int64 StorageManager::get_language_pack_database_size() { int64 StorageManager::get_language_pack_database_size() {
int64 size = 0; int64 size = 0;
auto path = G()->shared_config().get_option_string("language_pack_database_path"); auto path = G()->get_option_string("language_pack_database_path");
if (!path.empty()) { if (!path.empty()) {
SqliteDb::with_db_path(path, [&size](CSlice path) { size += get_file_size(path); }); SqliteDb::with_db_path(path, [&size](CSlice path) { size += get_file_size(path); });
} }
@ -317,8 +316,7 @@ void StorageManager::save_last_gc_timestamp() {
} }
void StorageManager::schedule_next_gc() { void StorageManager::schedule_next_gc() {
if (!G()->shared_config().get_option_boolean("use_storage_optimizer") && if (!G()->get_option_boolean("use_storage_optimizer") && !G()->parameters().enable_storage_optimizer) {
!G()->parameters().enable_storage_optimizer) {
next_gc_at_ = 0; next_gc_at_ = 0;
cancel_timeout(); cancel_timeout();
LOG(INFO) << "No next file clean up is scheduled"; LOG(INFO) << "No next file clean up is scheduled";

View File

@ -8,7 +8,6 @@
#include "td/telegram/ChannelId.h" #include "td/telegram/ChannelId.h"
#include "td/telegram/ConfigManager.h" #include "td/telegram/ConfigManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ContactsManager.h" #include "td/telegram/ContactsManager.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
#include "td/telegram/Td.h" #include "td/telegram/Td.h"
@ -181,11 +180,11 @@ void dismiss_suggested_action(SuggestedAction action, Promise<Unit> &&promise) {
if (action.otherwise_relogin_days_ <= 0) { if (action.otherwise_relogin_days_ <= 0) {
return promise.set_error(Status::Error(400, "Invalid authorization_delay specified")); return promise.set_error(Status::Error(400, "Invalid authorization_delay specified"));
} }
auto days = narrow_cast<int32>(G()->shared_config().get_option_integer("otherwise_relogin_days")); auto days = narrow_cast<int32>(G()->get_option_integer("otherwise_relogin_days"));
if (days == action.otherwise_relogin_days_) { if (days == action.otherwise_relogin_days_) {
vector<SuggestedAction> removed_actions{SuggestedAction{SuggestedAction::Type::SetPassword, DialogId(), days}}; vector<SuggestedAction> removed_actions{SuggestedAction{SuggestedAction::Type::SetPassword, DialogId(), days}};
send_closure(G()->td(), &Td::send_update, get_update_suggested_actions_object({}, removed_actions)); send_closure(G()->td(), &Td::send_update, get_update_suggested_actions_object({}, removed_actions));
G()->shared_config().set_option_empty("otherwise_relogin_days"); G()->set_option_empty("otherwise_relogin_days");
} }
return promise.set_value(Unit()); return promise.set_value(Unit());
} }

View File

@ -2646,8 +2646,7 @@ void Td::on_online_updated(bool force, bool send_update) {
} }
if (is_online_) { if (is_online_) {
alarm_timeout_.set_timeout_in( alarm_timeout_.set_timeout_in(
ONLINE_ALARM_ID, ONLINE_ALARM_ID, static_cast<double>(G()->get_option_integer("online_update_period_ms", 210000)) * 1e-3);
static_cast<double>(G()->shared_config().get_option_integer("online_update_period_ms", 210000)) * 1e-3);
} else { } else {
alarm_timeout_.cancel_timeout(ONLINE_ALARM_ID); alarm_timeout_.cancel_timeout(ONLINE_ALARM_ID);
} }
@ -2762,7 +2761,7 @@ void Td::set_is_online(bool is_online) {
} }
void Td::set_is_bot_online(bool is_bot_online) { void Td::set_is_bot_online(bool is_bot_online) {
if (G()->shared_config().get_option_integer("session_count") > 1) { if (G()->get_option_integer("session_count") > 1) {
is_bot_online = false; is_bot_online = false;
} }
@ -3654,15 +3653,14 @@ void Td::init(Result<TdDb::OpenedDatabase> r_opened_database) {
} }
}); });
options_.language_pack = G()->shared_config().get_option_string("localization_target"); options_.language_pack = G()->get_option_string("localization_target");
options_.language_code = G()->shared_config().get_option_string("language_pack_id"); options_.language_code = G()->get_option_string("language_pack_id");
options_.parameters = G()->shared_config().get_option_string("connection_parameters"); options_.parameters = G()->get_option_string("connection_parameters");
options_.tz_offset = static_cast<int32>(G()->shared_config().get_option_integer("utc_time_offset")); options_.tz_offset = static_cast<int32>(G()->get_option_integer("utc_time_offset"));
options_.is_emulator = G()->shared_config().get_option_boolean("is_emulator"); options_.is_emulator = G()->get_option_boolean("is_emulator");
// options_.proxy = Proxy(); // options_.proxy = Proxy();
G()->set_mtproto_header(make_unique<MtprotoHeader>(options_)); G()->set_mtproto_header(make_unique<MtprotoHeader>(options_));
G()->set_store_all_files_in_files_directory( G()->set_store_all_files_in_files_directory(G()->get_option_boolean("store_all_files_in_files_directory"));
G()->shared_config().get_option_boolean("store_all_files_in_files_directory"));
VLOG(td_init) << "Create NetQueryDispatcher"; VLOG(td_init) << "Create NetQueryDispatcher";
auto net_query_dispatcher = make_unique<NetQueryDispatcher>([&] { return create_reference(); }); auto net_query_dispatcher = make_unique<NetQueryDispatcher>([&] { return create_reference(); });
@ -3681,7 +3679,7 @@ void Td::init(Result<TdDb::OpenedDatabase> r_opened_database) {
init_managers(); init_managers();
G()->set_my_id(G()->shared_config().get_option_integer("my_id")); G()->set_my_id(G()->get_option_integer("my_id"));
storage_manager_ = create_actor<StorageManager>("StorageManager", create_reference(), G()->get_gc_scheduler_id()); storage_manager_ = create_actor<StorageManager>("StorageManager", create_reference(), G()->get_gc_scheduler_id());
G()->set_storage_manager(storage_manager_.get()); G()->set_storage_manager(storage_manager_.get());
@ -3807,7 +3805,9 @@ void Td::init_options_and_network() {
G()->set_state_manager(state_manager_.get()); G()->set_state_manager(state_manager_.get());
VLOG(td_init) << "Create ConfigShared"; VLOG(td_init) << "Create ConfigShared";
G()->set_shared_config(td::make_unique<ConfigShared>(G()->td_db()->get_config_pmc_shared())); auto config_shared = td::make_unique<ConfigShared>(G()->td_db()->get_config_pmc_shared());
auto config_shared_ptr = config_shared.get();
G()->set_shared_config(std::move(config_shared));
init_connection_creator(); init_connection_creator();
@ -3841,7 +3841,7 @@ void Td::init_options_and_network() {
// we need to process td_api::getOption along with td_api::setOption for consistency // we need to process td_api::getOption along with td_api::setOption for consistency
// we need to process td_api::setOption before managers and MTProto header are created, // we need to process td_api::setOption before managers and MTProto header are created,
// because their initialiation may be affected by the options // because their initialiation may be affected by the options
G()->shared_config().set_callback(make_unique<ConfigSharedCallback>()); config_shared_ptr->set_callback(make_unique<ConfigSharedCallback>());
} }
void Td::init_connection_creator() { void Td::init_connection_creator() {
@ -4846,7 +4846,7 @@ void Td::on_request(uint64 id, td_api::optimizeStorage &request) {
} }
void Td::on_request(uint64 id, td_api::getNetworkStatistics &request) { void Td::on_request(uint64 id, td_api::getNetworkStatistics &request) {
if (!request.only_current_ && G()->shared_config().get_option_boolean("disable_persistent_network_statistics")) { if (!request.only_current_ && G()->get_option_boolean("disable_persistent_network_statistics")) {
return send_error_raw(id, 400, "Persistent network statistics is disabled"); return send_error_raw(id, 400, "Persistent network statistics is disabled");
} }
CREATE_REQUEST_PROMISE(); CREATE_REQUEST_PROMISE();
@ -5632,7 +5632,7 @@ void Td::on_request(uint64 id, const td_api::createCall &request) {
return send_error_raw(id, r_input_user.error().code(), r_input_user.error().message()); return send_error_raw(id, r_input_user.error().code(), r_input_user.error().message());
} }
if (!G()->shared_config().get_option_boolean("calls_enabled")) { if (!G()->get_option_boolean("calls_enabled")) {
return send_error_raw(id, 400, "Calls are not enabled for the current user"); return send_error_raw(id, 400, "Calls are not enabled for the current user");
} }

View File

@ -8,7 +8,6 @@
#include "td/telegram/AccessRights.h" #include "td/telegram/AccessRights.h"
#include "td/telegram/AuthManager.h" #include "td/telegram/AuthManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ContactsManager.h" #include "td/telegram/ContactsManager.h"
#include "td/telegram/DialogId.h" #include "td/telegram/DialogId.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
@ -296,7 +295,7 @@ void TopDialogManager::update_rating_e_decay() {
if (!is_active_) { if (!is_active_) {
return; return;
} }
rating_e_decay_ = narrow_cast<int32>(G()->shared_config().get_option_integer("rating_e_decay", rating_e_decay_)); rating_e_decay_ = narrow_cast<int32>(G()->get_option_integer("rating_e_decay", rating_e_decay_));
} }
template <class StorerT> template <class StorerT>
@ -463,11 +462,11 @@ void TopDialogManager::on_get_top_peers(Result<telegram_api::object_ptr<telegram
// nothing to do // nothing to do
break; break;
case telegram_api::contacts_topPeersDisabled::ID: case telegram_api::contacts_topPeersDisabled::ID:
G()->shared_config().set_option_boolean("disable_top_chats", true); G()->set_option_boolean("disable_top_chats", true);
set_is_enabled(false); // apply immediately set_is_enabled(false); // apply immediately
break; break;
case telegram_api::contacts_topPeers::ID: { case telegram_api::contacts_topPeers::ID: {
G()->shared_config().set_option_empty("disable_top_chats"); G()->set_option_empty("disable_top_chats");
set_is_enabled(true); // apply immediately set_is_enabled(true); // apply immediately
auto top_peers = move_tl_object_as<telegram_api::contacts_topPeers>(std::move(top_peers_parent)); auto top_peers = move_tl_object_as<telegram_api::contacts_topPeers>(std::move(top_peers_parent));
@ -531,7 +530,7 @@ void TopDialogManager::init() {
} }
is_active_ = G()->parameters().use_chat_info_db && !td_->auth_manager_->is_bot(); is_active_ = G()->parameters().use_chat_info_db && !td_->auth_manager_->is_bot();
is_enabled_ = !G()->shared_config().get_option_boolean("disable_top_chats"); is_enabled_ = !G()->get_option_boolean("disable_top_chats");
update_rating_e_decay(); update_rating_e_decay();
string need_update_top_peers = G()->td_db()->get_binlog_pmc()->get("top_peers_enabled"); string need_update_top_peers = G()->td_db()->get_binlog_pmc()->get("top_peers_enabled");

View File

@ -14,7 +14,6 @@
#include "td/telegram/ChannelId.h" #include "td/telegram/ChannelId.h"
#include "td/telegram/ChatId.h" #include "td/telegram/ChatId.h"
#include "td/telegram/ConfigManager.h" #include "td/telegram/ConfigManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ContactsManager.h" #include "td/telegram/ContactsManager.h"
#include "td/telegram/DialogAction.h" #include "td/telegram/DialogAction.h"
#include "td/telegram/DialogId.h" #include "td/telegram/DialogId.h"
@ -1553,7 +1552,7 @@ void UpdatesManager::on_get_difference(tl_object_ptr<telegram_api::updates_Diffe
break; break;
} }
case telegram_api::updates_differenceTooLong::ID: { case telegram_api::updates_differenceTooLong::ID: {
if (G()->shared_config().get_option_integer("session_count") <= 1) { if (G()->get_option_integer("session_count") <= 1) {
LOG(ERROR) << "Receive differenceTooLong"; LOG(ERROR) << "Receive differenceTooLong";
} }
// TODO // TODO
@ -2261,8 +2260,8 @@ void UpdatesManager::add_pending_pts_update(tl_object_ptr<telegram_api::Update>
if (old_pts > new_pts - pts_count) { if (old_pts > new_pts - pts_count) {
LOG(WARNING) << "Have old_pts (= " << old_pts << ") + pts_count (= " << pts_count << ") > new_pts (= " << new_pts LOG(WARNING) << "Have old_pts (= " << old_pts << ") + pts_count (= " << pts_count << ") > new_pts (= " << new_pts
<< "). Logged in " << G()->shared_config().get_option_integer("authorization_date") << ". Update from " << "). Logged in " << G()->get_option_integer("authorization_date") << ". Update from " << source
<< source << " = " << oneline(to_string(update)); << " = " << oneline(to_string(update));
postpone_pts_update(std::move(update), new_pts, pts_count, receive_time, std::move(promise)); postpone_pts_update(std::move(update), new_pts, pts_count, receive_time, std::move(promise));
set_pts_gap_timeout(0.001); set_pts_gap_timeout(0.001);
return; return;
@ -2276,9 +2275,8 @@ void UpdatesManager::add_pending_pts_update(tl_object_ptr<telegram_api::Update>
if (old_pts > accumulated_pts_ - accumulated_pts_count_) { if (old_pts > accumulated_pts_ - accumulated_pts_count_) {
LOG(WARNING) << "Have old_pts (= " << old_pts << ") + accumulated_pts_count (= " << accumulated_pts_count_ LOG(WARNING) << "Have old_pts (= " << old_pts << ") + accumulated_pts_count (= " << accumulated_pts_count_
<< ") > accumulated_pts (= " << accumulated_pts_ << "). new_pts = " << new_pts << ") > accumulated_pts (= " << accumulated_pts_ << "). new_pts = " << new_pts
<< ", pts_count = " << pts_count << ". Logged in " << ", pts_count = " << pts_count << ". Logged in " << G()->get_option_integer("authorization_date")
<< G()->shared_config().get_option_integer("authorization_date") << ". Update from " << source << " = " << ". Update from " << source << " = " << oneline(to_string(update));
<< oneline(to_string(update));
postpone_pts_update(std::move(update), new_pts, pts_count, receive_time, std::move(promise)); postpone_pts_update(std::move(update), new_pts, pts_count, receive_time, std::move(promise));
set_pts_gap_timeout(0.001); set_pts_gap_timeout(0.001);
return; return;

View File

@ -6,7 +6,6 @@
// //
#include "td/telegram/files/FileGcParameters.h" #include "td/telegram/files/FileGcParameters.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
#include "td/utils/format.h" #include "td/utils/format.h"
@ -21,17 +20,16 @@ FileGcParameters::FileGcParameters(int64 size, int32 ttl, int32 count, int32 imm
, owner_dialog_ids_(std::move(owner_dialog_ids)) , owner_dialog_ids_(std::move(owner_dialog_ids))
, exclude_owner_dialog_ids_(std::move(exclude_owner_dialog_ids)) , exclude_owner_dialog_ids_(std::move(exclude_owner_dialog_ids))
, dialog_limit_(dialog_limit) { , dialog_limit_(dialog_limit) {
auto &config = G()->shared_config(); max_files_size_ = size >= 0 ? size : G()->get_option_integer("storage_max_files_size", 100 << 10) << 10;
max_files_size_ = size >= 0 ? size : config.get_option_integer("storage_max_files_size", 100 << 10) << 10;
max_time_from_last_access_ = max_time_from_last_access_ =
ttl >= 0 ? ttl : narrow_cast<int32>(config.get_option_integer("storage_max_time_from_last_access", 60 * 60 * 23)); ttl >= 0 ? ttl : narrow_cast<int32>(G()->get_option_integer("storage_max_time_from_last_access", 60 * 60 * 23));
max_file_count_ = count >= 0 ? count : narrow_cast<int32>(config.get_option_integer("storage_max_file_count", 40000)); max_file_count_ = count >= 0 ? count : narrow_cast<int32>(G()->get_option_integer("storage_max_file_count", 40000));
immunity_delay_ = immunity_delay >= 0 immunity_delay_ = immunity_delay >= 0
? immunity_delay ? immunity_delay
: narrow_cast<int32>(config.get_option_integer("storage_immunity_delay", 60 * 60)); : narrow_cast<int32>(G()->get_option_integer("storage_immunity_delay", 60 * 60));
} }
StringBuilder &operator<<(StringBuilder &string_builder, const FileGcParameters &parameters) { StringBuilder &operator<<(StringBuilder &string_builder, const FileGcParameters &parameters) {

View File

@ -6,7 +6,6 @@
// //
#include "td/telegram/files/FileLoadManager.h" #include "td/telegram/files/FileLoadManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
#include "td/telegram/net/DcId.h" #include "td/telegram/net/DcId.h"
#include "td/telegram/TdParameters.h" #include "td/telegram/TdParameters.h"
@ -29,7 +28,7 @@ void FileLoadManager::start_up() {
!G()->parameters().use_file_db /*tdlib_engine*/ !G()->parameters().use_file_db /*tdlib_engine*/
? ResourceManager::Mode::Greedy ? ResourceManager::Mode::Greedy
: ResourceManager::Mode::Baseline); : ResourceManager::Mode::Baseline);
if (G()->shared_config().get_option_boolean("is_premium")) { if (G()->get_option_boolean("is_premium")) {
max_download_resource_limit_ *= 8; max_download_resource_limit_ *= 8;
} }
} }

View File

@ -6,7 +6,6 @@
// //
#include "td/telegram/files/FileManager.h" #include "td/telegram/files/FileManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/DownloadManager.h" #include "td/telegram/DownloadManager.h"
#include "td/telegram/FileReferenceManager.h" #include "td/telegram/FileReferenceManager.h"
#include "td/telegram/files/FileData.h" #include "td/telegram/files/FileData.h"
@ -998,7 +997,7 @@ Status FileManager::check_local_location(FullLocalFileLocation &location, int64
return get_file_size_error(" for a photo"); return get_file_size_error(" for a photo");
} }
if (location.file_type_ == FileType::VideoNote && if (location.file_type_ == FileType::VideoNote &&
size > G()->shared_config().get_option_integer("video_note_size_max", DEFAULT_VIDEO_NOTE_SIZE_MAX)) { size > G()->get_option_integer("video_note_size_max", DEFAULT_VIDEO_NOTE_SIZE_MAX)) {
return get_file_size_error(" for a video note"); return get_file_size_error(" for a video note");
} }
return Status::OK(); return Status::OK();
@ -2026,7 +2025,7 @@ bool FileManager::set_encryption_key(FileId file_id, FileEncryptionKey key) {
} }
bool FileManager::set_content(FileId file_id, BufferSlice bytes) { bool FileManager::set_content(FileId file_id, BufferSlice bytes) {
if (G()->shared_config().get_option_boolean("ignore_inline_thumbnails")) { if (G()->get_option_boolean("ignore_inline_thumbnails")) {
return false; return false;
} }
@ -3168,7 +3167,7 @@ Result<FileId> FileManager::get_input_file_id(FileType type, const tl_object_ptr
return FileId(); return FileId();
} }
string hash; string hash;
if (G()->shared_config().get_option_boolean("reuse_uploaded_photos_by_hash") && new_type == FileType::Photo) { if (G()->get_option_boolean("reuse_uploaded_photos_by_hash") && new_type == FileType::Photo) {
auto r_stat = stat(path); auto r_stat = stat(path);
if (r_stat.is_ok() && r_stat.ok().size_ > 0 && r_stat.ok().size_ < 11000000) { if (r_stat.is_ok() && r_stat.ok().size_ > 0 && r_stat.ok().size_ < 11000000) {
auto r_file_content = read_file_str(path, r_stat.ok().size_); auto r_file_content = read_file_str(path, r_stat.ok().size_);

View File

@ -7,7 +7,6 @@
#include "td/telegram/net/ConnectionCreator.h" #include "td/telegram/net/ConnectionCreator.h"
#include "td/telegram/ConfigManager.h" #include "td/telegram/ConfigManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
#include "td/telegram/logevent/LogEvent.h" #include "td/telegram/logevent/LogEvent.h"
#include "td/telegram/MessagesManager.h" #include "td/telegram/MessagesManager.h"
@ -234,7 +233,7 @@ void ConnectionCreator::get_proxy_link(int32 proxy_id, Promise<string> promise)
} }
auto &proxy = it->second; auto &proxy = it->second;
string url = G()->shared_config().get_option_string("t_me_url", "https://t.me/"); string url = G()->get_option_string("t_me_url", "https://t.me/");
bool is_socks = false; bool is_socks = false;
switch (proxy.type()) { switch (proxy.type()) {
case Proxy::Type::Socks5: case Proxy::Type::Socks5:
@ -269,7 +268,7 @@ void ConnectionCreator::get_proxy_link(int32 proxy_id, Promise<string> promise)
} }
ActorId<GetHostByNameActor> ConnectionCreator::get_dns_resolver() { ActorId<GetHostByNameActor> ConnectionCreator::get_dns_resolver() {
if (G()->shared_config().get_option_boolean("expect_blocking", true)) { if (G()->get_option_boolean("expect_blocking", true)) {
if (block_get_host_by_name_actor_.empty()) { if (block_get_host_by_name_actor_.empty()) {
VLOG(connections) << "Init block bypass DNS resolver"; VLOG(connections) << "Init block bypass DNS resolver";
GetHostByNameActor::Options options; GetHostByNameActor::Options options;
@ -297,7 +296,7 @@ void ConnectionCreator::ping_proxy(int32 proxy_id, Promise<double> promise) {
CHECK(!close_flag_); CHECK(!close_flag_);
if (proxy_id == 0) { if (proxy_id == 0) {
auto main_dc_id = G()->net_query_dispatcher().get_main_dc_id(); auto main_dc_id = G()->net_query_dispatcher().get_main_dc_id();
bool prefer_ipv6 = G()->shared_config().get_option_boolean("prefer_ipv6"); bool prefer_ipv6 = G()->get_option_boolean("prefer_ipv6");
auto infos = dc_options_set_.find_all_connections(main_dc_id, false, false, prefer_ipv6, false); auto infos = dc_options_set_.find_all_connections(main_dc_id, false, false, prefer_ipv6, false);
if (infos.empty()) { if (infos.empty()) {
return promise.set_error(Status::Error(400, "Can't find valid DC address")); return promise.set_error(Status::Error(400, "Can't find valid DC address"));
@ -344,7 +343,7 @@ void ConnectionCreator::ping_proxy(int32 proxy_id, Promise<double> promise) {
return promise.set_error(Status::Error(400, "Unknown proxy identifier")); return promise.set_error(Status::Error(400, "Unknown proxy identifier"));
} }
const Proxy &proxy = it->second; const Proxy &proxy = it->second;
bool prefer_ipv6 = G()->shared_config().get_option_boolean("prefer_ipv6"); bool prefer_ipv6 = G()->get_option_boolean("prefer_ipv6");
send_closure(get_dns_resolver(), &GetHostByNameActor::run, proxy.server().str(), proxy.port(), prefer_ipv6, send_closure(get_dns_resolver(), &GetHostByNameActor::run, proxy.server().str(), proxy.port(), prefer_ipv6,
PromiseCreator::lambda([actor_id = actor_id(this), promise = std::move(promise), PromiseCreator::lambda([actor_id = actor_id(this), promise = std::move(promise),
proxy_id](Result<IPAddress> result) mutable { proxy_id](Result<IPAddress> result) mutable {
@ -413,9 +412,9 @@ void ConnectionCreator::ping_proxy_buffered_socket_fd(IPAddress ip_address, Buff
void ConnectionCreator::set_active_proxy_id(int32 proxy_id, bool from_binlog) { void ConnectionCreator::set_active_proxy_id(int32 proxy_id, bool from_binlog) {
active_proxy_id_ = proxy_id; active_proxy_id_ = proxy_id;
if (proxy_id == 0) { if (proxy_id == 0) {
G()->shared_config().set_option_empty("enabled_proxy_id"); G()->set_option_empty("enabled_proxy_id");
} else { } else {
G()->shared_config().set_option_integer("enabled_proxy_id", proxy_id); G()->set_option_integer("enabled_proxy_id", proxy_id);
} }
if (!from_binlog) { if (!from_binlog) {
if (proxy_id == 0) { if (proxy_id == 0) {
@ -701,8 +700,7 @@ Result<mtproto::TransportType> ConnectionCreator::get_transport_type(const Proxy
Result<SocketFd> ConnectionCreator::find_connection(const Proxy &proxy, const IPAddress &proxy_ip_address, DcId dc_id, Result<SocketFd> ConnectionCreator::find_connection(const Proxy &proxy, const IPAddress &proxy_ip_address, DcId dc_id,
bool allow_media_only, FindConnectionExtra &extra) { bool allow_media_only, FindConnectionExtra &extra) {
extra.debug_str = PSTRING() << "Failed to find valid IP address for " << dc_id; extra.debug_str = PSTRING() << "Failed to find valid IP address for " << dc_id;
bool prefer_ipv6 = bool prefer_ipv6 = G()->get_option_boolean("prefer_ipv6") || (proxy.use_proxy() && proxy_ip_address.is_ipv6());
G()->shared_config().get_option_boolean("prefer_ipv6") || (proxy.use_proxy() && proxy_ip_address.is_ipv6());
bool only_http = proxy.use_http_caching_proxy(); bool only_http = proxy.use_http_caching_proxy();
#if TD_DARWIN_WATCH_OS #if TD_DARWIN_WATCH_OS
only_http = true; only_http = true;
@ -1281,7 +1279,7 @@ void ConnectionCreator::loop() {
if (resolve_proxy_query_token_ == 0) { if (resolve_proxy_query_token_ == 0) {
resolve_proxy_query_token_ = next_token(); resolve_proxy_query_token_ = next_token();
const Proxy &proxy = proxies_[active_proxy_id_]; const Proxy &proxy = proxies_[active_proxy_id_];
bool prefer_ipv6 = G()->shared_config().get_option_boolean("prefer_ipv6"); bool prefer_ipv6 = G()->get_option_boolean("prefer_ipv6");
VLOG(connections) << "Resolve IP address " << resolve_proxy_query_token_ << " of " << proxy.server(); VLOG(connections) << "Resolve IP address " << resolve_proxy_query_token_ << " of " << proxy.server();
send_closure( send_closure(
get_dns_resolver(), &GetHostByNameActor::run, proxy.server().str(), proxy.port(), prefer_ipv6, get_dns_resolver(), &GetHostByNameActor::run, proxy.server().str(), proxy.port(), prefer_ipv6,

View File

@ -6,7 +6,6 @@
// //
#include "td/telegram/net/NetQueryDispatcher.h" #include "td/telegram/net/NetQueryDispatcher.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
#include "td/telegram/net/AuthDataShared.h" #include "td/telegram/net/AuthDataShared.h"
#include "td/telegram/net/DcAuthManager.h" #include "td/telegram/net/DcAuthManager.h"
@ -47,7 +46,7 @@ void NetQueryDispatcher::dispatch(NetQueryPtr net_query) {
net_query->set_error(Global::request_aborted_error()); net_query->set_error(Global::request_aborted_error());
return complete_net_query(std::move(net_query)); return complete_net_query(std::move(net_query));
} }
if (G()->shared_config().get_option_boolean("test_flood_wait")) { if (G()->get_option_boolean("test_flood_wait")) {
net_query->set_error(Status::Error(429, "Too Many Requests: retry after 10")); net_query->set_error(Status::Error(429, "Too Many Requests: retry after 10"));
return complete_net_query(std::move(net_query)); return complete_net_query(std::move(net_query));
// if (net_query->is_ok() && net_query->tl_constructor() == 0x0d9d75a4) { // if (net_query->is_ok() && net_query->tl_constructor() == 0x0d9d75a4) {
@ -168,7 +167,7 @@ Status NetQueryDispatcher::wait_dc_init(DcId dc_id, bool force) {
int32 slow_net_scheduler_id = G()->get_slow_net_scheduler_id(); int32 slow_net_scheduler_id = G()->get_slow_net_scheduler_id();
auto raw_dc_id = dc_id.get_raw_id(); auto raw_dc_id = dc_id.get_raw_id();
bool is_premium = G()->shared_config().get_option_boolean("is_premium"); bool is_premium = G()->get_option_boolean("is_premium");
int32 upload_session_count = (raw_dc_id != 2 && raw_dc_id != 4) || is_premium ? 8 : 4; int32 upload_session_count = (raw_dc_id != 2 && raw_dc_id != 4) || is_premium ? 8 : 4;
int32 download_session_count = is_premium ? 8 : 2; int32 download_session_count = is_premium ? 8 : 2;
int32 download_small_session_count = is_premium ? 8 : 2; int32 download_small_session_count = is_premium ? 8 : 2;
@ -278,11 +277,11 @@ bool NetQueryDispatcher::is_dc_inited(int32 raw_dc_id) {
} }
int32 NetQueryDispatcher::get_session_count() { int32 NetQueryDispatcher::get_session_count() {
return max(narrow_cast<int32>(G()->shared_config().get_option_integer("session_count")), 1); return max(narrow_cast<int32>(G()->get_option_integer("session_count")), 1);
} }
bool NetQueryDispatcher::get_use_pfs() { bool NetQueryDispatcher::get_use_pfs() {
return G()->shared_config().get_option_boolean("use_pfs") || get_session_count() > 1; return G()->get_option_boolean("use_pfs") || get_session_count() > 1;
} }
NetQueryDispatcher::NetQueryDispatcher(const std::function<ActorShared<>()> &create_reference) { NetQueryDispatcher::NetQueryDispatcher(const std::function<ActorShared<>()> &create_reference) {

View File

@ -6,7 +6,6 @@
// //
#include "td/telegram/net/NetStatsManager.h" #include "td/telegram/net/NetStatsManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
#include "td/telegram/logevent/LogEvent.h" #include "td/telegram/logevent/LogEvent.h"
#include "td/telegram/StateManager.h" #include "td/telegram/StateManager.h"
@ -213,7 +212,7 @@ void NetStatsManager::start_up() {
auto since_str = G()->td_db()->get_binlog_pmc()->get("net_stats_since"); auto since_str = G()->td_db()->get_binlog_pmc()->get("net_stats_since");
if (!since_str.empty()) { if (!since_str.empty()) {
auto since = to_integer<int32>(since_str); auto since = to_integer<int32>(since_str);
auto authorization_date = G()->shared_config().get_option_integer("authorization_date"); auto authorization_date = G()->get_option_integer("authorization_date");
if (unix_time < since) { if (unix_time < since) {
since_total_ = unix_time; since_total_ = unix_time;
G()->td_db()->get_binlog_pmc()->set("net_stats_since", to_string(since_total_)); G()->td_db()->get_binlog_pmc()->set("net_stats_since", to_string(since_total_));
@ -290,7 +289,7 @@ void NetStatsManager::update(NetStatsInfo &info, bool force_save) {
} }
void NetStatsManager::save_stats(NetStatsInfo &info, NetType net_type) { void NetStatsManager::save_stats(NetStatsInfo &info, NetType net_type) {
if (G()->shared_config().get_option_boolean("disable_persistent_network_statistics")) { if (G()->get_option_boolean("disable_persistent_network_statistics")) {
return; return;
} }