From 3318ffdb20a22b84e8e7f210e92e04ff3426179b Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 17 Aug 2022 16:11:13 +0300 Subject: [PATCH] Proxy all option-related requests through G. --- td/telegram/AnimationsManager.cpp | 5 +- td/telegram/AuthManager.cpp | 12 +- td/telegram/BackgroundManager.cpp | 3 +- td/telegram/CallActor.cpp | 7 +- td/telegram/ConfigManager.cpp | 63 +++++---- td/telegram/ConfigManager.h | 21 ++- td/telegram/ContactsManager.cpp | 25 ++-- td/telegram/DialogFilter.cpp | 3 +- td/telegram/Global.cpp | 40 ++++++ td/telegram/Global.h | 24 +++- td/telegram/LanguagePackManager.cpp | 19 ++- td/telegram/LinkManager.cpp | 8 +- td/telegram/MessageContent.cpp | 3 +- td/telegram/MessageEntity.cpp | 6 +- td/telegram/MessageReaction.cpp | 17 ++- td/telegram/MessagesManager.cpp | 64 +++++---- td/telegram/NotificationManager.cpp | 30 ++--- td/telegram/NotificationSettingsManager.cpp | 7 +- td/telegram/OptionManager.cpp | 137 +++++++++----------- td/telegram/PasswordManager.cpp | 3 +- td/telegram/Premium.cpp | 13 +- td/telegram/RestrictionReason.cpp | 6 +- td/telegram/SecretChatsManager.cpp | 3 +- td/telegram/SponsoredMessageManager.cpp | 3 +- td/telegram/StickersManager.cpp | 41 +++--- td/telegram/StorageManager.cpp | 6 +- td/telegram/SuggestedAction.cpp | 5 +- td/telegram/Td.cpp | 30 ++--- td/telegram/TopDialogManager.cpp | 9 +- td/telegram/UpdatesManager.cpp | 12 +- td/telegram/files/FileGcParameters.cpp | 10 +- td/telegram/files/FileLoadManager.cpp | 3 +- td/telegram/files/FileManager.cpp | 7 +- td/telegram/net/ConnectionCreator.cpp | 18 ++- td/telegram/net/NetQueryDispatcher.cpp | 9 +- td/telegram/net/NetStatsManager.cpp | 5 +- 36 files changed, 334 insertions(+), 343 deletions(-) diff --git a/td/telegram/AnimationsManager.cpp b/td/telegram/AnimationsManager.cpp index 4afd6e32e..329a3b8b6 100644 --- a/td/telegram/AnimationsManager.cpp +++ b/td/telegram/AnimationsManager.cpp @@ -7,7 +7,6 @@ #include "td/telegram/AnimationsManager.h" #include "td/telegram/AuthManager.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/DialogId.h" #include "td/telegram/Document.h" #include "td/telegram/DocumentsManager.h" @@ -412,7 +411,7 @@ void AnimationsManager::on_update_animation_search_emojis(string animation_searc return; } if (td_->auth_manager_->is_bot()) { - G()->shared_config().set_option_empty("animation_search_emojis"); + G()->set_option_empty("animation_search_emojis"); return; } @@ -430,7 +429,7 @@ void AnimationsManager::on_update_animation_search_provider(string animation_sea return; } if (td_->auth_manager_->is_bot()) { - G()->shared_config().set_option_empty("animation_search_provider"); + G()->set_option_empty("animation_search_provider"); return; } diff --git a/td/telegram/AuthManager.cpp b/td/telegram/AuthManager.cpp index d5f37e452..1c48bae00 100644 --- a/td/telegram/AuthManager.cpp +++ b/td/telegram/AuthManager.cpp @@ -9,7 +9,6 @@ #include "td/telegram/AttachMenuManager.h" #include "td/telegram/AuthManager.hpp" #include "td/telegram/ConfigManager.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/ContactsManager.h" #include "td/telegram/Global.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()) { // just in case 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); } else { LOG(ERROR) << "Restore unknown my_id"; @@ -701,8 +700,7 @@ void AuthManager::on_log_out_result(NetQueryPtr &result) { if (r_log_out.is_ok()) { auto logged_out = r_log_out.move_as_ok(); if (!logged_out->future_auth_token_.empty()) { - G()->shared_config().set_option_string("authentication_token", - base64url_encode(logged_out->future_auth_token_.as_slice())); + G()->set_option_string("authentication_token", base64url_encode(logged_out->future_auth_token_.as_slice())); } } else { status = r_log_out.move_as_error(); @@ -792,7 +790,7 @@ void AuthManager::on_get_authorization(tl_object_ptr(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_) { 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_ptrflags_ & 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) { - 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_->messages_manager_->on_authorization_success(); diff --git a/td/telegram/BackgroundManager.cpp b/td/telegram/BackgroundManager.cpp index 4f8813baf..844d8abb8 100644 --- a/td/telegram/BackgroundManager.cpp +++ b/td/telegram/BackgroundManager.cpp @@ -8,7 +8,6 @@ #include "td/telegram/AuthManager.h" #include "td/telegram/BackgroundType.hpp" -#include "td/telegram/ConfigShared.h" #include "td/telegram/DialogId.h" #include "td/telegram/Document.h" #include "td/telegram/DocumentsManager.h" @@ -453,7 +452,7 @@ void BackgroundManager::get_backgrounds(bool for_dark_theme, Result BackgroundManager::get_background_url(const string &name, td_api::object_ptr background_type) { 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(); if (type.has_file()) { url += name; diff --git a/td/telegram/CallActor.cpp b/td/telegram/CallActor.cpp index 64def5a85..3f4f8e894 100644 --- a/td/telegram/CallActor.cpp +++ b/td/telegram/CallActor.cpp @@ -6,7 +6,6 @@ // #include "td/telegram/CallActor.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/ContactsManager.h" #include "td/telegram/DhCache.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) { call_state_.is_received = 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(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() { call_state_.type = CallState::Type::ExchangingKey; 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(call_receive_timeout_ms) * 0.001; LOG(INFO) << "Set call timeout to " << timeout; set_timeout_in(timeout); @@ -773,7 +772,7 @@ void CallActor::try_send_request_query() { call_state_.protocol.get_input_phone_call_protocol()); auto query = G()->net_query_creator().create(tl_query); 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(call_receive_timeout_ms) * 0.001; LOG(INFO) << "Set call timeout to " << timeout; set_timeout_in(timeout); diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index cb6f095b3..6ae066c60 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -7,7 +7,6 @@ #include "td/telegram/ConfigManager.h" #include "td/telegram/AuthManager.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/ConnectionState.h" #include "td/telegram/Global.h" #include "td/telegram/JsonValue.h" @@ -244,7 +243,7 @@ static ActorOwn<> get_simple_config_impl(Promise promise, in #endif } -ActorOwn<> get_simple_config_azure(Promise promise, const ConfigShared *shared_config, bool is_test, +ActorOwn<> get_simple_config_azure(Promise promise, const Global *shared_config, bool is_test, int32 scheduler_id) { string url = PSTRING() << "https://software-download.microsoft.com/" << (is_test ? "test" : "prod") << "v2/config.txt"; @@ -255,7 +254,7 @@ ActorOwn<> get_simple_config_azure(Promise promise, const Co } static ActorOwn<> get_simple_config_dns(Slice address, Slice host, Promise 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"); const bool prefer_ipv6 = shared_config == nullptr ? false : shared_config->get_option_boolean("prefer_ipv6"); if (name.empty()) { @@ -307,14 +306,14 @@ static ActorOwn<> get_simple_config_dns(Slice address, Slice host, Promise get_simple_config_google_dns(Promise promise, const ConfigShared *shared_config, - bool is_test, int32 scheduler_id) { +ActorOwn<> get_simple_config_google_dns(Promise promise, const Global *shared_config, bool is_test, + int32 scheduler_id) { return get_simple_config_dns("dns.google/resolve", "dns.google", std::move(promise), shared_config, is_test, scheduler_id); } -ActorOwn<> get_simple_config_mozilla_dns(Promise promise, const ConfigShared *shared_config, - bool is_test, int32 scheduler_id) { +ActorOwn<> get_simple_config_mozilla_dns(Promise promise, const Global *shared_config, bool is_test, + int32 scheduler_id) { return get_simple_config_dns("mozilla.cloudflare-dns.com/dns-query", "mozilla.cloudflare-dns.com", std::move(promise), shared_config, is_test, scheduler_id); } @@ -329,9 +328,8 @@ static string generate_firebase_remote_config_payload() { << app_instance_id << "\"}"; } -ActorOwn<> get_simple_config_firebase_remote_config(Promise promise, - const ConfigShared *shared_config, bool is_test, - int32 scheduler_id) { +ActorOwn<> get_simple_config_firebase_remote_config(Promise promise, const Global *shared_config, + bool is_test, int32 scheduler_id) { if (is_test) { promise.set_error(Status::Error(400, "Test config is not supported")); return ActorOwn<>(); @@ -355,7 +353,7 @@ ActorOwn<> get_simple_config_firebase_remote_config(Promise {}, prefer_ipv6, std::move(get_config), payload, "application/json"); } -ActorOwn<> get_simple_config_firebase_realtime(Promise promise, const ConfigShared *shared_config, +ActorOwn<> get_simple_config_firebase_realtime(Promise promise, const Global *shared_config, bool is_test, int32 scheduler_id) { if (is_test) { promise.set_error(Status::Error(400, "Test config is not supported")); @@ -371,7 +369,7 @@ ActorOwn<> get_simple_config_firebase_realtime(Promise promi prefer_ipv6, std::move(get_config)); } -ActorOwn<> get_simple_config_firebase_firestore(Promise promise, const ConfigShared *shared_config, +ActorOwn<> get_simple_config_firebase_firestore(Promise promise, const Global *shared_config, bool is_test, int32 scheduler_id) { if (is_test) { 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(); VLOG(config_recoverer) << "Receive raw " << to_string(config); 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(); for (auto &rule : config->rules_) { @@ -708,7 +706,7 @@ class ConfigRecoverer final : public Actor { } 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 { @@ -842,8 +840,7 @@ class ConfigRecoverer final : public Actor { return get_simple_config_mozilla_dns; } }(); - simple_config_query_ = - get_simple_config(std::move(promise), &G()->shared_config(), G()->is_test_dc(), G()->get_gc_scheduler_id()); + simple_config_query_ = get_simple_config(std::move(promise), G(), G()->is_test_dc(), G()->get_gc_scheduler_id()); 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) { - G()->shared_config().set_option_boolean("ignore_sensitive_content_restrictions", - ignore_sensitive_content_restrictions); - bool have_ignored_restriction_reasons = G()->shared_config().have_option("ignored_restriction_reasons"); + G()->set_option_boolean("ignore_sensitive_content_restrictions", ignore_sensitive_content_restrictions); + bool have_ignored_restriction_reasons = G()->have_option("ignored_restriction_reasons"); if (have_ignored_restriction_reasons != ignore_sensitive_content_restrictions) { reget_app_config(Auto()); } @@ -1113,7 +1109,7 @@ void ConfigManager::do_set_archive_and_mute(bool archive_and_mute) { if (archive_and_mute) { 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) { @@ -1211,7 +1207,7 @@ void ConfigManager::on_result(NetQueryPtr res) { if (result_ptr.is_error()) { fail_promises(set_content_settings_queries_[ignore_sensitive_content_restrictions], result_ptr.move_as_error()); } 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) { 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(); 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_); return; @@ -1328,7 +1324,7 @@ void ConfigManager::process_config(tl_object_ptr config) { set_timeout_at(expire_time_.at()); 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. 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 &c CHECK(config != nullptr); LOG(INFO) << "Receive app config " << to_string(config); - const bool archive_and_mute = - G()->shared_config().get_option_boolean("archive_and_mute_new_chats_from_unknown_users"); + const bool archive_and_mute = G()->get_option_boolean("archive_and_mute_new_chats_from_unknown_users"); string autologin_token; vector autologin_domains; @@ -1701,16 +1696,16 @@ void ConfigManager::process_app_config(tl_object_ptr &c auto setting_value = get_json_value_int(std::move(video_note_setting->value_), Slice()); if (setting_value > 0) { 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") { - 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") { - 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") { - G()->shared_config().set_option_integer("video_note_size_max", setting_value); + G()->set_option_integer("video_note_size_max", setting_value); } } } else { @@ -1740,17 +1735,17 @@ void ConfigManager::process_app_config(tl_object_ptr &c } if (key == "ringtone_duration_max") { 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; } if (key == "ringtone_size_max") { 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; } if (key == "ringtone_saved_count_max") { 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; } if (key == "premium_promo_order") { @@ -1774,7 +1769,7 @@ void ConfigManager::process_app_config(tl_object_ptr &c if (suffix == "_limit_default" || suffix == "_limit_premium") { auto setting_value = get_json_value_int(std::move(key_value->value_), key); if (setting_value > 0) { - G()->shared_config().set_option_integer(key, setting_value); + G()->set_option_integer(key, setting_value); } else { LOG(ERROR) << "Receive invalid value " << setting_value << " for " << key; } @@ -1817,7 +1812,7 @@ void ConfigManager::process_app_config(tl_object_ptr &c send_closure(G()->link_manager(), &LinkManager::update_autologin_domains, std::move(autologin_token), std::move(autologin_domains), std::move(url_auth_domains)); - ConfigShared &shared_config = G()->shared_config(); + Global &shared_config = *G(); if (ignored_restriction_reasons.empty()) { shared_config.set_option_empty("ignored_restriction_reasons"); diff --git a/td/telegram/ConfigManager.h b/td/telegram/ConfigManager.h index 272058c5f..9f6ddd01b 100644 --- a/td/telegram/ConfigManager.h +++ b/td/telegram/ConfigManager.h @@ -30,7 +30,7 @@ namespace td { extern int VERBOSITY_NAME(config_recoverer); -class ConfigShared; +class Global; using SimpleConfig = tl_object_ptr; struct SimpleConfigResult { @@ -40,23 +40,22 @@ struct SimpleConfigResult { Result decode_config(Slice input); -ActorOwn<> get_simple_config_azure(Promise promise, const ConfigShared *shared_config, bool is_test, +ActorOwn<> get_simple_config_azure(Promise promise, const Global *shared_config, bool is_test, int32 scheduler_id); -ActorOwn<> get_simple_config_google_dns(Promise promise, const ConfigShared *shared_config, - bool is_test, int32 scheduler_id); +ActorOwn<> get_simple_config_google_dns(Promise promise, const Global *shared_config, bool is_test, + int32 scheduler_id); -ActorOwn<> get_simple_config_mozilla_dns(Promise promise, const ConfigShared *shared_config, - bool is_test, int32 scheduler_id); +ActorOwn<> get_simple_config_mozilla_dns(Promise promise, const Global *shared_config, bool is_test, + int32 scheduler_id); -ActorOwn<> get_simple_config_firebase_remote_config(Promise promise, - const ConfigShared *shared_config, bool is_test, - int32 scheduler_id); +ActorOwn<> get_simple_config_firebase_remote_config(Promise promise, const Global *shared_config, + bool is_test, int32 scheduler_id); -ActorOwn<> get_simple_config_firebase_realtime(Promise promise, const ConfigShared *shared_config, +ActorOwn<> get_simple_config_firebase_realtime(Promise promise, const Global *shared_config, bool is_test, int32 scheduler_id); -ActorOwn<> get_simple_config_firebase_firestore(Promise promise, const ConfigShared *shared_config, +ActorOwn<> get_simple_config_firebase_firestore(Promise promise, const Global *shared_config, bool is_test, int32 scheduler_id); class HttpDate { diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index bf42b8ea9..c60fe5d3e 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -11,7 +11,6 @@ #include "td/telegram/BotMenuButton.h" #include "td/telegram/ChannelParticipantFilter.h" #include "td/telegram/ConfigManager.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/Dependencies.h" #include "td/telegram/DialogInviteLink.h" #include "td/telegram/DialogLocation.h" @@ -3333,11 +3332,11 @@ ContactsManager::ContactsManager(Td *td, ActorShared<> parent) : td_(td), parent my_id_ = load_my_id(); - G()->shared_config().set_option_integer("telegram_service_notifications_chat_id", - 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()->shared_config().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("telegram_service_notifications_chat_id", + DialogId(get_service_notifications_user_id()).get()); + G()->set_option_integer("replies_bot_chat_id", DialogId(get_replies_bot_user_id()).get()); + G()->set_option_integer("group_anonymous_bot_user_id", get_anonymous_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) { 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) { my_id_ = my_id; 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()); } } @@ -6037,7 +6036,7 @@ void ContactsManager::set_location(const Location &location, Promise &&pro } 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::max() : 0; if (pending_location_visibility_expire_date_ == -1 && 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() { auto expire_date = pending_location_visibility_expire_date_ != -1 ? pending_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, @@ -6490,7 +6489,7 @@ void ContactsManager::set_name(const string &first_name, const string &last_name } void ContactsManager::set_bio(const string &bio, Promise &&promise) { - auto max_bio_length = static_cast(G()->shared_config().get_option_integer("bio_length_max")); + auto max_bio_length = static_cast(G()->get_option_integer("bio_length_max")); auto new_bio = strip_empty_characters(bio, max_bio_length); for (auto &c : new_bio) { if (c == '\n') { @@ -8612,7 +8611,7 @@ void ContactsManager::on_get_user(tl_object_ptr &&user_ptr, if (flags & USER_FLAG_IS_ME) { set_my_id(user_id); 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) { CHECK(u != nullptr); if (user_id == get_my_id()) { - if (G()->shared_config().get_option_boolean("is_premium") != u->is_premium) { - G()->shared_config().set_option_boolean("is_premium", u->is_premium); + if (G()->get_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); } } diff --git a/td/telegram/DialogFilter.cpp b/td/telegram/DialogFilter.cpp index 87716feee..518e53022 100644 --- a/td/telegram/DialogFilter.cpp +++ b/td/telegram/DialogFilter.cpp @@ -6,7 +6,6 @@ // #include "td/telegram/DialogFilter.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/DialogId.h" #include "td/telegram/Global.h" @@ -20,7 +19,7 @@ namespace td { int32 DialogFilter::get_max_filter_dialogs() { - return narrow_cast(G()->shared_config().get_option_integer("chat_filter_chosen_chat_count_max", 100)); + return narrow_cast(G()->get_option_integer("chat_filter_chosen_chat_count_max", 100)); } unique_ptr DialogFilter::get_dialog_filter( diff --git a/td/telegram/Global.cpp b/td/telegram/Global.cpp index e8df3c801..4d79e6ac0 100644 --- a/td/telegram/Global.cpp +++ b/td/telegram/Global.cpp @@ -256,6 +256,46 @@ void Global::set_shared_config(unique_ptr 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 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) { const double PI = 3.14159265358979323846; latitude *= PI / 180; diff --git a/td/telegram/Global.h b/td/telegram/Global.h index 356c73a45..049403f07 100644 --- a/td/telegram/Global.h +++ b/td/telegram/Global.h @@ -28,6 +28,7 @@ #include #include #include +#include namespace td { @@ -129,10 +130,25 @@ class Global final : public ActorContext { void set_shared_config(unique_ptr shared_config); - ConfigShared &shared_config() { - CHECK(shared_config_.get() != nullptr); - return *shared_config_; - } + void set_option_empty(Slice name); + + 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 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 { return server_time_difference_was_updated_; diff --git a/td/telegram/LanguagePackManager.cpp b/td/telegram/LanguagePackManager.cpp index a1268dca2..ab535dc57 100644 --- a/td/telegram/LanguagePackManager.cpp +++ b/td/telegram/LanguagePackManager.cpp @@ -6,7 +6,6 @@ // #include "td/telegram/LanguagePackManager.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/Global.h" #include "td/telegram/logevent/LogEvent.h" #include "td/telegram/misc.h" @@ -202,12 +201,12 @@ LanguagePackManager::LanguageDatabase *LanguagePackManager::add_language_databas void LanguagePackManager::start_up() { std::lock_guard database_lock(language_database_mutex_); manager_count_++; - language_pack_ = G()->shared_config().get_option_string("localization_target"); - language_code_ = G()->shared_config().get_option_string("language_pack_id"); + language_pack_ = G()->get_option_string("localization_target"); + language_code_ = G()->get_option_string("language_pack_id"); CHECK(check_language_pack_name(language_pack_)); 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()) { auto language = add_language(database_, language_pack_, language_code_); if (language->version_ == -1) { @@ -339,7 +338,7 @@ vector LanguagePackManager::get_used_language_codes() { } 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_) { return; } @@ -350,7 +349,7 @@ void LanguagePackManager::on_language_pack_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_) { return; } @@ -374,7 +373,7 @@ void LanguagePackManager::on_language_pack_version_changed(bool is_base, int32 n if (new_version < 0) { Slice version_key = is_base ? Slice("base_language_pack_version") : Slice("language_pack_version"); - new_version = narrow_cast(G()->shared_config().get_option_integer(version_key, -1)); + new_version = narrow_cast(G()->get_option_integer(version_key, -1)); } if (new_version <= 0) { return; @@ -495,8 +494,8 @@ void LanguagePackManager::on_update_language_pack(tl_object_ptrshared_config().set_option_empty("language_pack_version"); - G()->shared_config().set_option_empty("base_language_pack_version"); + G()->set_option_empty("language_pack_version"); + G()->set_option_empty("base_language_pack_version"); if (!language_pack_.empty() && !language_code_.empty()) { 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) { - G()->shared_config().set_option_empty("base_language_pack_version"); + G()->set_option_empty("base_language_pack_version"); if (!base_language_code_.empty()) { add_language(database_, language_pack_, base_language_code_); on_language_pack_version_changed(true, std::numeric_limits::max()); diff --git a/td/telegram/LinkManager.cpp b/td/telegram/LinkManager.cpp index 25e777381..6886df6ec 100644 --- a/td/telegram/LinkManager.cpp +++ b/td/telegram/LinkManager.cpp @@ -10,7 +10,6 @@ #include "td/telegram/ChannelId.h" #include "td/telegram/ChannelType.h" #include "td/telegram/ConfigManager.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/ContactsManager.h" #include "td/telegram/DialogId.h" #include "td/telegram/DialogParticipant.h" @@ -254,8 +253,7 @@ class LinkManager::InternalLinkBotStart final : public InternalLink { td_api::object_ptr get_internal_link_type_object() const final { bool autostart = autostart_; - if (Scheduler::context() != nullptr && - bot_username_ == G()->shared_config().get_option_string("premium_bot_username")) { + if (Scheduler::context() != nullptr && bot_username_ == G()->get_option_string("premium_bot_username")) { autostart = true; } return td_api::make_object(bot_username_, start_parameter_, autostart); @@ -889,7 +887,7 @@ LinkManager::LinkInfo LinkManager::get_link_info(Slice link) { vector t_me_urls{Slice("t.me"), Slice("telegram.me"), Slice("telegram.dog")}; 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://")) { Slice t_me_url = cur_t_me_url; 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) { return PSTRING() << "tg:join?invite=" << hash; } 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; } } diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index a1d11b7ff..e50da18d3 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -14,7 +14,6 @@ #include "td/telegram/CallDiscardReason.h" #include "td/telegram/ChannelId.h" #include "td/telegram/ChatId.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/Contact.h" #include "td/telegram/ContactsManager.h" #include "td/telegram/Dependencies.h" @@ -4671,7 +4670,7 @@ unique_ptr dup_message_content(Td *td, DialogId dialog_id, const } case MessageContentType::Sticker: { auto result = make_unique(*static_cast(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)) { return std::move(result); } diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index 6d246d044..54e6c6c83 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -6,7 +6,6 @@ // #include "td/telegram/MessageEntity.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/ContactsManager.h" #include "td/telegram/Dependencies.h" #include "td/telegram/Global.h" @@ -4305,7 +4304,7 @@ Result get_formatted_text(const Td *td, DialogId dialog_id, 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); - 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, 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); } } - if (!G()->shared_config().get_option_boolean("is_premium") && - dialog_id != DialogId(td->contacts_manager_->get_my_id())) { + if (!G()->get_option_boolean("is_premium") && dialog_id != DialogId(td->contacts_manager_->get_my_id())) { remove_premium_custom_emoji_entities(td, text.entities, false); } } diff --git a/td/telegram/MessageReaction.cpp b/td/telegram/MessageReaction.cpp index 07389412a..e44225f05 100644 --- a/td/telegram/MessageReaction.cpp +++ b/td/telegram/MessageReaction.cpp @@ -8,7 +8,6 @@ #include "td/telegram/AccessRights.h" #include "td/telegram/ConfigManager.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/ContactsManager.h" #include "td/telegram/Global.h" #include "td/telegram/MessageSender.h" @@ -241,13 +240,13 @@ class SetDefaultReactionQuery final : public Td::ResultHandler { 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; if (default_reaction != reaction_) { send_set_default_reaction_query(td_); } 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; - 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()); } }; @@ -595,17 +594,17 @@ void set_default_reaction(Td *td, string reaction, Promise &&promise) { return promise.set_error(Status::Error(400, "Can't set incative reaction as default")); } - if (G()->shared_config().get_option_string("default_reaction", "-") != reaction) { - G()->shared_config().set_option_string("default_reaction", reaction); - if (!G()->shared_config().get_option_boolean("default_reaction_needs_sync")) { - G()->shared_config().set_option_boolean("default_reaction_needs_sync", true); + if (G()->get_option_string("default_reaction", "-") != reaction) { + G()->set_option_string("default_reaction", reaction); + if (!G()->get_option_boolean("default_reaction_needs_sync")) { + G()->set_option_boolean("default_reaction_needs_sync", true); } } promise.set_value(Unit()); } void send_set_default_reaction_query(Td *td) { - td->create_handler()->send(G()->shared_config().get_option_string("default_reaction")); + td->create_handler()->send(G()->get_option_string("default_reaction")); } } // namespace td diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 159f03c0a..19ef489ab 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -10,7 +10,6 @@ #include "td/telegram/ChainId.h" #include "td/telegram/ChannelType.h" #include "td/telegram/ChatId.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/ContactsManager.h" #include "td/telegram/Dependencies.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)), {{dialog_id, 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 result) { if (result.is_ok()) { 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( telegram_api::messages_startBot(std::move(bot_input_user), std::move(input_peer), random_id, parameter), {{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 result) { if (result.is_ok()) { 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, 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}}); - 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 result) { if (result.is_ok()) { 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), 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}}); - 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 result) { if (result.is_ok()) { 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(); switch (dialog_id.get_type()) { case DialogType::User: { - bool can_revoke_incoming = G()->shared_config().get_option_boolean("revoke_pm_inbox", true); - int64 revoke_time_limit = - G()->shared_config().get_option_integer("revoke_pm_time_limit", DEFAULT_REVOKE_TIME_LIMIT); + bool can_revoke_incoming = G()->get_option_boolean("revoke_pm_inbox", true); + int64 revoke_time_limit = G()->get_option_integer("revoke_pm_time_limit", DEFAULT_REVOKE_TIME_LIMIT); if (G()->unix_time_cached() - m->date < 86400 && content_type == MessageContentType::Dice) { return false; @@ -10710,7 +10708,7 @@ bool MessagesManager::can_revoke_message(DialogId dialog_id, const Message *m) c case DialogType::Chat: { bool is_appointed_administrator = 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) && 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())) { 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: // 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()}; @@ -11586,7 +11584,7 @@ int32 MessagesManager::get_unload_dialog_delay() const { CHECK(is_message_unload_enabled()); auto default_unload_delay = td_->auth_manager_->is_bot() ? DIALOG_UNLOAD_BOT_DELAY : DIALOG_UNLOAD_DELAY; - return narrow_cast(G()->shared_config().get_option_integer("message_unload_delay", default_unload_delay)); + return narrow_cast(G()->get_option_integer("message_unload_delay", default_unload_delay)); } int32 MessagesManager::get_next_unload_dialog_delay() const { @@ -13182,7 +13180,7 @@ void MessagesManager::init() { if (is_authorized && td_->auth_manager_->is_bot()) { 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) { 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()) { server_main_dialog_list_position_ = log_event.server_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)) { LOG(INFO) << "Ignore main chat list position " << server_main_dialog_list_position_ << '/' << main_dialog_list_position_; @@ -13583,7 +13581,7 @@ void MessagesManager::init() { void MessagesManager::on_authorization_success() { 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()) { disable_get_dialog_filter_ = true; @@ -17259,7 +17257,7 @@ void MessagesManager::on_get_dialog_filters(Resultshared_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; 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) { 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"); } @@ -18327,7 +18325,7 @@ Status MessagesManager::can_get_message_viewers(DialogId dialog_id, const Messag if (participant_count == 0) { 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"); } @@ -18745,7 +18743,7 @@ Result> MessagesManager::get_message_link(FullMessageId } 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) { auto *top_m = get_message_force(d, m->top_thread_message_id, "get_public_message_link"); @@ -19126,8 +19124,8 @@ Result> MessagesManager::create_dialog_filter(DialogFil void MessagesManager::create_dialog_filter(td_api::object_ptr filter, Promise> &&promise) { CHECK(!td_->auth_manager_->is_bot()); - auto max_dialog_filters = clamp(G()->shared_config().get_option_integer("chat_filter_count_max"), - static_cast(0), static_cast(100)); + auto max_dialog_filters = + clamp(G()->get_option_integer("chat_filter_count_max"), static_cast(0), static_cast(100)); if (dialog_filters_.size() >= narrow_cast(max_dialog_filters)) { return promise.set_error(Status::Error(400, "The maximum number of chat folders exceeded")); } @@ -19298,7 +19296,7 @@ void MessagesManager::reorder_dialog_filters(vector dialog_filte if (main_dialog_list_position < 0 || main_dialog_list_position > static_cast(dialog_filters_.size())) { 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; } @@ -19880,9 +19878,9 @@ int32 MessagesManager::get_pinned_dialogs_limit(DialogListId dialog_list_id) { key = Slice("pinned_archived_chat_count_max"); default_limit = 100; } - int32 limit = clamp(narrow_cast(G()->shared_config().get_option_integer(key)), 0, 1000); + int32 limit = clamp(narrow_cast(G()->get_option_integer(key)), 0, 1000); if (limit <= 0) { - if (G()->shared_config().get_option_boolean("is_premium")) { + if (G()->get_option_boolean("is_premium")) { default_limit *= 2; } return default_limit; @@ -22231,7 +22229,7 @@ td_api::object_ptr MessagesManager::get_dialog_message_ db_query.dialog_id = dialog_id; db_query.filter = filter; db_query.from_message_id = fixed_from_message_id; - db_query.tz_offset = static_cast(G()->shared_config().get_option_integer("utc_time_offset")); + db_query.tz_offset = static_cast(G()->get_option_integer("utc_time_offset")); G()->td_db()->get_messages_db_async()->get_dialog_message_calendar(db_query, std::move(new_promise)); return {}; } @@ -24333,8 +24331,8 @@ vector MessagesManager::get_message_available_reactions(const vector result; if (can_use_reactions) { - bool is_premium = G()->shared_config().get_option_boolean("is_premium"); - int64 reactions_uniq_max = G()->shared_config().get_option_integer("reactions_uniq_max", 11); + bool is_premium = G()->get_option_boolean("is_premium"); + int64 reactions_uniq_max = G()->get_option_integer("reactions_uniq_max", 11); bool can_add_new_reactions = m->reactions == nullptr || static_cast(m->reactions->reactions_.size()) < reactions_uniq_max; // can add only active available reactions or remove previously set reaction @@ -24887,7 +24885,7 @@ unique_ptr MessagesManager::create_message_to_send( m->is_copy = is_copy || m->forward_info != nullptr; 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; } else { m->disable_notification = d->notification_settings.silent_send_message; @@ -25497,7 +25495,7 @@ Result MessagesManager::process_input_message_content( 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)); 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()) { case DialogType::User: 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::SecretChat: return false; @@ -26759,7 +26757,7 @@ bool MessagesManager::can_edit_message(DialogId dialog_id, const Message *m, boo if (has_edit_time_limit) { 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) { return false; } @@ -29264,7 +29262,7 @@ Result MessagesManager::get_messag } 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"); } @@ -30127,7 +30125,7 @@ bool MessagesManager::is_message_notification_disabled(const Dialog *d, const Me return true; } 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; } 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) { 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) { update_opened_message_content(message->content.get()); } diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index d9de73483..859d1e938 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -9,7 +9,6 @@ #include "td/telegram/AuthManager.h" #include "td/telegram/ChannelId.h" #include "td/telegram/ChatId.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/ContactsManager.h" #include "td/telegram/DeviceTokenManager.h" #include "td/telegram/Document.h" @@ -204,8 +203,7 @@ void NotificationManager::init() { return; } - disable_contact_registered_notifications_ = - G()->shared_config().get_option_boolean("disable_contact_registered_notifications"); + disable_contact_registered_notifications_ = G()->get_option_boolean("disable_contact_registered_notifications"); auto sync_state = G()->td_db()->get_binlog_pmc()->get(get_is_contact_registered_notifications_synchronized_key()); if (sync_state.empty()) { sync_state = "00"; @@ -2389,8 +2387,8 @@ void NotificationManager::on_notification_group_count_max_changed(bool send_upda return; } - auto new_max_notification_group_count = narrow_cast( - G()->shared_config().get_option_integer("notification_group_count_max", DEFAULT_GROUP_COUNT_MAX)); + auto new_max_notification_group_count = + narrow_cast(G()->get_option_integer("notification_group_count_max", DEFAULT_GROUP_COUNT_MAX)); CHECK(MIN_NOTIFICATION_GROUP_COUNT_MAX <= new_max_notification_group_count && new_max_notification_group_count <= MAX_NOTIFICATION_GROUP_COUNT_MAX); @@ -2453,8 +2451,8 @@ void NotificationManager::on_notification_group_size_max_changed() { return; } - auto new_max_notification_group_size = narrow_cast( - G()->shared_config().get_option_integer("notification_group_size_max", DEFAULT_GROUP_SIZE_MAX)); + auto new_max_notification_group_size = + narrow_cast(G()->get_option_integer("notification_group_size_max", DEFAULT_GROUP_SIZE_MAX)); CHECK(MIN_NOTIFICATION_GROUP_SIZE_MAX <= new_max_notification_group_size && new_max_notification_group_size <= MAX_NOTIFICATION_GROUP_SIZE_MAX); @@ -2536,8 +2534,8 @@ void NotificationManager::on_online_cloud_timeout_changed() { return; } - online_cloud_timeout_ms_ = narrow_cast( - G()->shared_config().get_option_integer("online_cloud_timeout_ms", DEFAULT_ONLINE_CLOUD_TIMEOUT_MS)); + online_cloud_timeout_ms_ = + narrow_cast(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_; } @@ -2546,8 +2544,8 @@ void NotificationManager::on_notification_cloud_delay_changed() { return; } - notification_cloud_delay_ms_ = narrow_cast( - G()->shared_config().get_option_integer("notification_cloud_delay_ms", DEFAULT_ONLINE_CLOUD_DELAY_MS)); + notification_cloud_delay_ms_ = + narrow_cast(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_; } @@ -2556,8 +2554,8 @@ void NotificationManager::on_notification_default_delay_changed() { return; } - notification_default_delay_ms_ = narrow_cast( - G()->shared_config().get_option_integer("notification_default_delay_ms", DEFAULT_DEFAULT_DELAY_MS)); + notification_default_delay_ms_ = + narrow_cast(G()->get_option_integer("notification_default_delay_ms", DEFAULT_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; } - 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_) { return; @@ -2585,9 +2583,9 @@ void NotificationManager::on_get_disable_contact_registered_notifications(bool i disable_contact_registered_notifications_ = 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 { - G()->shared_config().set_option_empty("disable_contact_registered_notifications"); + G()->set_option_empty("disable_contact_registered_notifications"); } } diff --git a/td/telegram/NotificationSettingsManager.cpp b/td/telegram/NotificationSettingsManager.cpp index 3d49ad02d..ac622cfb3 100644 --- a/td/telegram/NotificationSettingsManager.cpp +++ b/td/telegram/NotificationSettingsManager.cpp @@ -10,7 +10,6 @@ #include "td/telegram/AudiosManager.h" #include "td/telegram/AudiosManager.hpp" #include "td/telegram/AuthManager.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/ContactsManager.h" #include "td/telegram/Document.h" #include "td/telegram/DocumentsManager.h" @@ -874,7 +873,7 @@ void NotificationSettingsManager::add_saved_ringtone(td_api::object_ptrfile_manager_->get_file_view(file_id); 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")); } auto file_type = file_view.get_type(); @@ -889,7 +888,7 @@ void NotificationSettingsManager::add_saved_ringtone(td_api::object_ptr 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")); } 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_); - 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(max_count)) { // reload all saved ringtones to get ringtones besides the limit return reload_saved_ringtones(PromiseCreator::lambda([promise = std::move(promise)](Result &&result) mutable { diff --git a/td/telegram/OptionManager.cpp b/td/telegram/OptionManager.cpp index eb26c9733..ae8c95f90 100644 --- a/td/telegram/OptionManager.cpp +++ b/td/telegram/OptionManager.cpp @@ -10,7 +10,6 @@ #include "td/telegram/AttachMenuManager.h" #include "td/telegram/AuthManager.h" #include "td/telegram/ConfigManager.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/ContactsManager.h" #include "td/telegram/DialogId.h" #include "td/telegram/GitCommitHash.h" @@ -44,54 +43,52 @@ namespace td { OptionManager::OptionManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) { send_unix_time_update(); - if (G()->shared_config().have_option("language_database_path")) { - G()->shared_config().set_option_string("language_pack_database_path", - G()->shared_config().get_option_string("language_database_path")); - G()->shared_config().set_option_empty("language_database_path"); + if (G()->have_option("language_database_path")) { + G()->set_option_string("language_pack_database_path", G()->get_option_string("language_database_path")); + G()->set_option_empty("language_database_path"); } - if (G()->shared_config().have_option("language_pack")) { - G()->shared_config().set_option_string("localization_target", - G()->shared_config().get_option_string("language_pack")); - G()->shared_config().set_option_empty("language_pack"); + if (G()->have_option("language_pack")) { + G()->set_option_string("localization_target", G()->get_option_string("language_pack")); + G()->set_option_empty("language_pack"); } - if (G()->shared_config().have_option("language_code")) { - G()->shared_config().set_option_string("language_pack_id", G()->shared_config().get_option_string("language_code")); - G()->shared_config().set_option_empty("language_code"); + if (G()->have_option("language_code")) { + G()->set_option_string("language_pack_id", G()->get_option_string("language_code")); + G()->set_option_empty("language_code"); } - if (!G()->shared_config().have_option("message_text_length_max")) { - G()->shared_config().set_option_integer("message_text_length_max", 4096); + if (!G()->have_option("message_text_length_max")) { + G()->set_option_integer("message_text_length_max", 4096); } - if (!G()->shared_config().have_option("message_caption_length_max")) { - G()->shared_config().set_option_integer("message_caption_length_max", 1024); + if (!G()->have_option("message_caption_length_max")) { + G()->set_option_integer("message_caption_length_max", 1024); } - if (!G()->shared_config().have_option("bio_length_max")) { - G()->shared_config().set_option_integer("bio_length_max", 70); + if (!G()->have_option("bio_length_max")) { + G()->set_option_integer("bio_length_max", 70); } - if (!G()->shared_config().have_option("suggested_video_note_length")) { - G()->shared_config().set_option_integer("suggested_video_note_length", 384); + if (!G()->have_option("suggested_video_note_length")) { + G()->set_option_integer("suggested_video_note_length", 384); } - if (!G()->shared_config().have_option("suggested_video_note_video_bitrate")) { - G()->shared_config().set_option_integer("suggested_video_note_video_bitrate", 1000); + if (!G()->have_option("suggested_video_note_video_bitrate")) { + G()->set_option_integer("suggested_video_note_video_bitrate", 1000); } - if (!G()->shared_config().have_option("suggested_video_note_audio_bitrate")) { - G()->shared_config().set_option_integer("suggested_video_note_audio_bitrate", 64); + if (!G()->have_option("suggested_video_note_audio_bitrate")) { + G()->set_option_integer("suggested_video_note_audio_bitrate", 64); } - if (!G()->shared_config().have_option("notification_sound_duration_max")) { - G()->shared_config().set_option_integer("notification_sound_duration_max", 5); + if (!G()->have_option("notification_sound_duration_max")) { + G()->set_option_integer("notification_sound_duration_max", 5); } - if (!G()->shared_config().have_option("notification_sound_size_max")) { - G()->shared_config().set_option_integer("notification_sound_size_max", 307200); + if (!G()->have_option("notification_sound_size_max")) { + G()->set_option_integer("notification_sound_size_max", 307200); } - if (!G()->shared_config().have_option("notification_sound_count_max")) { - G()->shared_config().set_option_integer("notification_sound_count_max", G()->is_test_dc() ? 5 : 100); + if (!G()->have_option("notification_sound_count_max")) { + G()->set_option_integer("notification_sound_count_max", G()->is_test_dc() ? 5 : 100); } - if (!G()->shared_config().have_option("chat_filter_count_max")) { - G()->shared_config().set_option_integer("chat_filter_count_max", G()->is_test_dc() ? 3 : 10); + if (!G()->have_option("chat_filter_count_max")) { + 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")) { - G()->shared_config().set_option_integer("chat_filter_chosen_chat_count_max", G()->is_test_dc() ? 5 : 100); + if (!G()->have_option("chat_filter_chosen_chat_count_max")) { + 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() { @@ -118,7 +115,7 @@ void OptionManager::on_update_server_time_difference() { } 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)) { send_closure( 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 } 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") { - 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") { - send_closure(td_->auth_manager_actor_, &AuthManager::on_authorization_lost, - G()->shared_config().get_option_string(name)); + send_closure(td_->auth_manager_actor_, &AuthManager::on_authorization_lost, G()->get_option_string(name)); } break; case 'b': @@ -216,13 +212,13 @@ void OptionManager::on_option_updated(const string &name) { break; case 'c': 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(); } } break; 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_); } if (name == "dice_emojis") { @@ -240,7 +236,7 @@ void OptionManager::on_option_updated(const string &name) { } if (name == "disable_top_chats") { send_closure(td_->top_dialog_manager_actor_, &TopDialogManager::update_is_enabled, - !G()->shared_config().get_option_boolean(name)); + !G()->get_option_boolean(name)); } break; case 'e': @@ -250,8 +246,7 @@ void OptionManager::on_option_updated(const string &name) { break; case 'f': if (name == "favorite_stickers_limit") { - td_->stickers_manager_->on_update_favorite_stickers_limit( - narrow_cast(G()->shared_config().get_option_integer(name))); + td_->stickers_manager_->on_update_favorite_stickers_limit(narrow_cast(G()->get_option_integer(name))); } break; 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); } 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(); } } @@ -267,7 +262,7 @@ void OptionManager::on_option_updated(const string &name) { case 'l': if (name == "language_pack_id") { 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(); } send_closure(td_->attach_menu_manager_actor_, &AttachMenuManager::reload_attach_menu_bots, Promise()); @@ -277,14 +272,14 @@ void OptionManager::on_option_updated(const string &name) { } if (name == "localization_target") { 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(); } } break; case 'm': 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; 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); } if (name == "otherwise_relogin_days") { - auto days = narrow_cast(G()->shared_config().get_option_integer(name)); + auto days = narrow_cast(G()->get_option_integer(name)); if (days > 0) { vector added_actions{SuggestedAction{SuggestedAction::Type::SetPassword, DialogId(), days}}; 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); } if (name == "recent_stickers_limit") { - td_->stickers_manager_->on_update_recent_stickers_limit( - narrow_cast(G()->shared_config().get_option_integer(name))); + td_->stickers_manager_->on_update_recent_stickers_limit(narrow_cast(G()->get_option_integer(name))); } break; case 's': if (name == "saved_animations_limit") { - td_->animations_manager_->on_update_saved_animations_limit( - narrow_cast(G()->shared_config().get_option_integer(name))); + td_->animations_manager_->on_update_saved_animations_limit(narrow_cast(G()->get_option_integer(name))); } if (name == "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); } if (name == "utc_time_offset") { - if (G()->mtproto_header().set_tz_offset(static_cast(G()->shared_config().get_option_integer(name)))) { + if (G()->mtproto_header().set_tz_offset(static_cast(G()->get_option_integer(name)))) { 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 - td_->send_update( - td_api::make_object(name, get_option_value_object(G()->shared_config().get_option(name)))); + td_->send_update(td_api::make_object(name, get_option_value_object(G()->get_option(name)))); } void OptionManager::get_option(const string &name, Promise> &&promise) { @@ -363,7 +355,7 @@ void OptionManager::get_option(const string &name, Promiseshared_config().get_option(name))); + promise.set_value(get_option_value_object(G()->get_option(name))); }); }; switch (name[0]) { @@ -434,7 +426,7 @@ void OptionManager::set_option(const string &name, td_api::object_ptrshared_config().set_option_empty(option_name); + G()->set_option_empty(option_name); } else { if (value_constructor_id != td_api::optionValueInteger::ID) { 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_ptrshared_config().set_option_integer(name, int_value); + G()->set_option_integer(name, int_value); } promise.set_value(Unit()); return true; @@ -459,7 +451,7 @@ void OptionManager::set_option(const string &name, td_api::object_ptrshared_config().set_option_empty(name); + G()->set_option_empty(name); } else { if (value_constructor_id != td_api::optionValueBoolean::ID) { 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(value.get())->value_; - G()->shared_config().set_option_boolean(name, bool_value); + G()->set_option_boolean(name, bool_value); } promise.set_value(Unit()); return true; @@ -478,7 +470,7 @@ void OptionManager::set_option(const string &name, td_api::object_ptrshared_config().set_option_empty(name); + G()->set_option_empty(name); } else { if (value_constructor_id != td_api::optionValueString::ID) { 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(value.get())->value_; if (str_value.empty()) { - G()->shared_config().set_option_empty(name); + G()->set_option_empty(name); } else { if (check_value(str_value)) { - G()->shared_config().set_option_string(name, str_value); + G()->set_option_string(name, str_value); } else { promise.set_error(Status::Error(400, PSLICE() << "Option \"" << name << "\" can't have specified value")); return false; @@ -583,7 +575,7 @@ void OptionManager::set_option(const string &name, td_api::object_ptrshared_config().get_option_boolean("can_ignore_sensitive_content_restrictions")) { + if (!G()->get_option_boolean("can_ignore_sensitive_content_restrictions")) { return promise.set_error( 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_ptrshared_config().set_option_boolean(name, - static_cast(value.get())->value_); + G()->set_option_boolean(name, static_cast(value.get())->value_); break; case td_api::optionValueEmpty::ID: - G()->shared_config().set_option_empty(name); + G()->set_option_empty(name); break; case td_api::optionValueInteger::ID: - G()->shared_config().set_option_integer(name, - static_cast(value.get())->value_); + G()->set_option_integer(name, static_cast(value.get())->value_); break; case td_api::optionValueString::ID: - G()->shared_config().set_option_string(name, - static_cast(value.get())->value_); + G()->set_option_string(name, static_cast(value.get())->value_); break; default: UNREACHABLE(); @@ -767,7 +756,7 @@ void OptionManager::get_current_state(vector> updates.push_back(td_api::make_object("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)) { updates.push_back( td_api::make_object(option.first, get_option_value_object(option.second))); diff --git a/td/telegram/PasswordManager.cpp b/td/telegram/PasswordManager.cpp index 5ebb0c8b1..e95900e03 100644 --- a/td/telegram/PasswordManager.cpp +++ b/td/telegram/PasswordManager.cpp @@ -7,7 +7,6 @@ #include "td/telegram/PasswordManager.h" #include "td/telegram/ConfigManager.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/DhCache.h" #include "td/telegram/DialogId.h" #include "td/telegram/Global.h" @@ -785,7 +784,7 @@ void PasswordManager::do_get_state(Promise promise) { state.has_recovery_email_address = password->has_recovery_; state.has_secure_values = password->has_secure_values_; - auto days = narrow_cast(G()->shared_config().get_option_integer("otherwise_relogin_days")); + auto days = narrow_cast(G()->get_option_integer("otherwise_relogin_days")); if (days > 0) { dismiss_suggested_action(SuggestedAction{SuggestedAction::Type::SetPassword, DialogId(), days}, Promise()); diff --git a/td/telegram/Premium.cpp b/td/telegram/Premium.cpp index edb773dbf..857bcefee 100644 --- a/td/telegram/Premium.cpp +++ b/td/telegram/Premium.cpp @@ -8,7 +8,6 @@ #include "td/telegram/AnimationsManager.h" #include "td/telegram/Application.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/ContactsManager.h" #include "td/telegram/DialogId.h" #include "td/telegram/Document.h" @@ -398,10 +397,8 @@ static string get_premium_source(const td_api::object_ptr } static td_api::object_ptr get_premium_limit_object(Slice key) { - int32 default_limit = - static_cast(G()->shared_config().get_option_integer(PSLICE() << key << "_limit_default")); - int32 premium_limit = - static_cast(G()->shared_config().get_option_integer(PSLICE() << key << "_limit_premium")); + int32 default_limit = static_cast(G()->get_option_integer(PSLICE() << key << "_limit_default")); + int32 premium_limit = static_cast(G()->get_option_integer(PSLICE() << key << "_limit_premium")); if (default_limit <= 0 || premium_limit <= default_limit) { return nullptr; } @@ -454,7 +451,7 @@ void get_premium_limit(const td_api::object_ptr &limit void get_premium_features(Td *td, const td_api::object_ptr &source, Promise> &&promise) { auto premium_features = - full_split(G()->shared_config().get_option_string( + full_split(G()->get_option_string( "premium_features", "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"), @@ -486,11 +483,11 @@ void get_premium_features(Td *td, const td_api::object_ptr 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()) { payment_link = td_api::make_object(premium_bot_username, source_str, true); } 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()) { payment_link = td_api::make_object(premium_invoice_slug); } diff --git a/td/telegram/RestrictionReason.cpp b/td/telegram/RestrictionReason.cpp index 0ed1af374..c23d895fb 100644 --- a/td/telegram/RestrictionReason.cpp +++ b/td/telegram/RestrictionReason.cpp @@ -6,7 +6,6 @@ // #include "td/telegram/RestrictionReason.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/Global.h" #include "td/utils/algorithm.h" @@ -22,10 +21,9 @@ string get_restriction_reason_description(const vector &restr return string(); } - auto ignored_restriction_reasons = - full_split(G()->shared_config().get_option_string("ignored_restriction_reasons"), ','); + auto ignored_restriction_reasons = full_split(G()->get_option_string("ignored_restriction_reasons"), ','); auto platform = [] { - if (G()->shared_config().get_option_boolean("ignore_platform_restrictions")) { + if (G()->get_option_boolean("ignore_platform_restrictions")) { return Slice(); } diff --git a/td/telegram/SecretChatsManager.cpp b/td/telegram/SecretChatsManager.cpp index 696e4bd68..4883c09f4 100644 --- a/td/telegram/SecretChatsManager.cpp +++ b/td/telegram/SecretChatsManager.cpp @@ -6,7 +6,6 @@ // #include "td/telegram/SecretChatsManager.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/ContactsManager.h" #include "td/telegram/DhCache.h" #include "td/telegram/EncryptedFile.h" @@ -321,7 +320,7 @@ unique_ptr SecretChatsManager::make_secret_chat_contex } 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 { diff --git a/td/telegram/SponsoredMessageManager.cpp b/td/telegram/SponsoredMessageManager.cpp index 6ce90206e..dbb3e43a4 100644 --- a/td/telegram/SponsoredMessageManager.cpp +++ b/td/telegram/SponsoredMessageManager.cpp @@ -7,7 +7,6 @@ #include "td/telegram/SponsoredMessageManager.h" #include "td/telegram/ChannelId.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/ContactsManager.h" #include "td/telegram/Global.h" #include "td/telegram/LinkManager.h" @@ -169,7 +168,7 @@ td_api::object_ptr SponsoredMessageManager::get_sponso case DialogType::Channel: if (sponsored_message.server_message_id.is_valid()) { 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( PSTRING() << t_me << "c/" << channel_id.get() << '/' << sponsored_message.server_message_id.get()); } diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 23c388681..7179d0bf6 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -10,7 +10,6 @@ #include "td/telegram/AuthManager.h" #include "td/telegram/AvailableReaction.h" #include "td/telegram/ConfigManager.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/ContactsManager.h" #include "td/telegram/DialogId.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_recent_stickers_limit( - narrow_cast(G()->shared_config().get_option_integer("recent_stickers_limit", 200))); - on_update_favorite_stickers_limit( - narrow_cast(G()->shared_config().get_option_integer("favorite_stickers_limit", 5))); + on_update_recent_stickers_limit(narrow_cast(G()->get_option_integer("recent_stickers_limit", 200))); + on_update_favorite_stickers_limit(narrow_cast(G()->get_option_integer("favorite_stickers_limit", 5))); next_click_animated_emoji_message_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()); load_special_sticker_set_info_from_binlog(sticker_set); - dice_emojis_str_ = - G()->shared_config().get_option_string("dice_emojis", "🎲\x01🎯\x01🏀\x01⚽\x01⚽️\x01🎰\x01🎳"); + dice_emojis_str_ = G()->get_option_string("dice_emojis", "🎲\x01🎯\x01🏀\x01⚽\x01⚽️\x01🎰\x01🎳"); dice_emojis_ = full_split(dice_emojis_str_, '\x01'); for (auto &dice_emoji : dice_emojis_) { auto &animated_dice_sticker_set = add_special_sticker_set(SpecialStickerSetType::animated_dice(dice_emoji)); @@ -1473,9 +1469,9 @@ void StickersManager::init() { G()->td_db()->get_binlog_pmc()->erase("invalidate_old_featured_sticker_sets"); } - 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()->shared_config().set_option_empty("animated_emoji_sticker_set_name"); // legacy + G()->td_db()->get_binlog_pmc()->erase("animated_dice_sticker_set"); // legacy + G()->set_option_empty("animated_dice_sticker_set_name"); // legacy + G()->set_option_empty("animated_emoji_sticker_set_name"); // legacy } void StickersManager::reload_reactions() { @@ -2234,7 +2230,7 @@ tl_object_ptr StickersManager::get_sticker_set_info_obje vector regular_sticker_ids; vector premium_sticker_ids; 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; if (premium_sticker_ids.size() > max_premium_stickers) { premium_sticker_ids.resize(max_premium_stickers); @@ -4114,8 +4110,8 @@ vector StickersManager::get_stickers(StickerType sticker_type, string em vector regular_sticker_ids; vector premium_sticker_ids; std::tie(regular_sticker_ids, premium_sticker_ids) = split_stickers_by_premium(result); - if (G()->shared_config().get_option_boolean("is_premium") || allow_premium) { - auto normal_count = G()->shared_config().get_option_integer("stickers_normal_by_emoji_per_premium_num", 2); + if (G()->get_option_boolean("is_premium") || allow_premium) { + auto normal_count = G()->get_option_integer("stickers_normal_by_emoji_per_premium_num", 2); if (normal_count < 0) { normal_count = 2; } @@ -4150,7 +4146,7 @@ vector StickersManager::get_stickers(StickerType sticker_type, string em } } 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) { for (const auto &sticker_id : premium_sticker_ids) { LOG(INFO) << "Add premium sticker " << sticker_id << " from installed sticker set"; @@ -5014,15 +5010,14 @@ void StickersManager::on_update_dice_emojis() { return; } if (td_->auth_manager_->is_bot()) { - G()->shared_config().set_option_empty("dice_emojis"); + G()->set_option_empty("dice_emojis"); return; } if (!is_inited_) { return; } - auto dice_emojis_str = - G()->shared_config().get_option_string("dice_emojis", "🎲\x01🎯\x01🏀\x01⚽\x01⚽️\x01🎰\x01🎳"); + auto dice_emojis_str = G()->get_option_string("dice_emojis", "🎲\x01🎯\x01🏀\x01⚽\x01⚽️\x01🎰\x01🎳"); if (dice_emojis_str == dice_emojis_str_) { return; } @@ -5054,15 +5049,14 @@ void StickersManager::on_update_dice_success_values() { return; } if (td_->auth_manager_->is_bot()) { - G()->shared_config().set_option_empty("dice_success_values"); + G()->set_option_empty("dice_success_values"); return; } if (!is_inited_) { return; } - auto dice_success_values_str = - G()->shared_config().get_option_string("dice_success_values", "0,6:62,5:110,5:110,5:110,64:110,6:110"); + 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"); if (dice_success_values_str == dice_success_values_str_) { return; } @@ -5080,7 +5074,7 @@ void StickersManager::on_update_emoji_sounds() { 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_) { return; } @@ -5127,7 +5121,7 @@ void StickersManager::on_update_disable_animated_emojis() { 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_) { return; } @@ -7908,8 +7902,7 @@ void StickersManager::save_recent_stickers_to_database(bool is_attached) { } void StickersManager::on_update_animated_emoji_zoom() { - animated_emoji_zoom_ = - static_cast(G()->shared_config().get_option_integer("animated_emoji_zoom", 625000000)) * 1e-9; + animated_emoji_zoom_ = static_cast(G()->get_option_integer("animated_emoji_zoom", 625000000)) * 1e-9; } void StickersManager::on_update_recent_stickers_limit(int32 recent_stickers_limit) { diff --git a/td/telegram/StorageManager.cpp b/td/telegram/StorageManager.cpp index c0272e45c..946e24435 100644 --- a/td/telegram/StorageManager.cpp +++ b/td/telegram/StorageManager.cpp @@ -6,7 +6,6 @@ // #include "td/telegram/StorageManager.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/DialogId.h" #include "td/telegram/files/FileGcWorker.h" #include "td/telegram/files/FileStatsWorker.h" @@ -188,7 +187,7 @@ int64 StorageManager::get_database_size() { int64 StorageManager::get_language_pack_database_size() { 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()) { 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() { - if (!G()->shared_config().get_option_boolean("use_storage_optimizer") && - !G()->parameters().enable_storage_optimizer) { + if (!G()->get_option_boolean("use_storage_optimizer") && !G()->parameters().enable_storage_optimizer) { next_gc_at_ = 0; cancel_timeout(); LOG(INFO) << "No next file clean up is scheduled"; diff --git a/td/telegram/SuggestedAction.cpp b/td/telegram/SuggestedAction.cpp index 212ccabd5..fb4b4e3b0 100644 --- a/td/telegram/SuggestedAction.cpp +++ b/td/telegram/SuggestedAction.cpp @@ -8,7 +8,6 @@ #include "td/telegram/ChannelId.h" #include "td/telegram/ConfigManager.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/ContactsManager.h" #include "td/telegram/Global.h" #include "td/telegram/Td.h" @@ -181,11 +180,11 @@ void dismiss_suggested_action(SuggestedAction action, Promise &&promise) { if (action.otherwise_relogin_days_ <= 0) { return promise.set_error(Status::Error(400, "Invalid authorization_delay specified")); } - auto days = narrow_cast(G()->shared_config().get_option_integer("otherwise_relogin_days")); + auto days = narrow_cast(G()->get_option_integer("otherwise_relogin_days")); if (days == action.otherwise_relogin_days_) { vector removed_actions{SuggestedAction{SuggestedAction::Type::SetPassword, DialogId(), days}}; 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()); } diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 0a6fd07f5..4026534c7 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -2646,8 +2646,7 @@ void Td::on_online_updated(bool force, bool send_update) { } if (is_online_) { alarm_timeout_.set_timeout_in( - ONLINE_ALARM_ID, - static_cast(G()->shared_config().get_option_integer("online_update_period_ms", 210000)) * 1e-3); + ONLINE_ALARM_ID, static_cast(G()->get_option_integer("online_update_period_ms", 210000)) * 1e-3); } else { 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) { - if (G()->shared_config().get_option_integer("session_count") > 1) { + if (G()->get_option_integer("session_count") > 1) { is_bot_online = false; } @@ -3654,15 +3653,14 @@ void Td::init(Result r_opened_database) { } }); - options_.language_pack = G()->shared_config().get_option_string("localization_target"); - options_.language_code = G()->shared_config().get_option_string("language_pack_id"); - options_.parameters = G()->shared_config().get_option_string("connection_parameters"); - options_.tz_offset = static_cast(G()->shared_config().get_option_integer("utc_time_offset")); - options_.is_emulator = G()->shared_config().get_option_boolean("is_emulator"); + options_.language_pack = G()->get_option_string("localization_target"); + options_.language_code = G()->get_option_string("language_pack_id"); + options_.parameters = G()->get_option_string("connection_parameters"); + options_.tz_offset = static_cast(G()->get_option_integer("utc_time_offset")); + options_.is_emulator = G()->get_option_boolean("is_emulator"); // options_.proxy = Proxy(); G()->set_mtproto_header(make_unique(options_)); - G()->set_store_all_files_in_files_directory( - G()->shared_config().get_option_boolean("store_all_files_in_files_directory")); + G()->set_store_all_files_in_files_directory(G()->get_option_boolean("store_all_files_in_files_directory")); VLOG(td_init) << "Create NetQueryDispatcher"; auto net_query_dispatcher = make_unique([&] { return create_reference(); }); @@ -3681,7 +3679,7 @@ void Td::init(Result r_opened_database) { 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", create_reference(), G()->get_gc_scheduler_id()); G()->set_storage_manager(storage_manager_.get()); @@ -3807,7 +3805,9 @@ void Td::init_options_and_network() { G()->set_state_manager(state_manager_.get()); VLOG(td_init) << "Create ConfigShared"; - G()->set_shared_config(td::make_unique(G()->td_db()->get_config_pmc_shared())); + auto config_shared = td::make_unique(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(); @@ -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::setOption before managers and MTProto header are created, // because their initialiation may be affected by the options - G()->shared_config().set_callback(make_unique()); + config_shared_ptr->set_callback(make_unique()); } 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) { - 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"); } 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()); } - 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"); } diff --git a/td/telegram/TopDialogManager.cpp b/td/telegram/TopDialogManager.cpp index 679b54ede..e57752cd0 100644 --- a/td/telegram/TopDialogManager.cpp +++ b/td/telegram/TopDialogManager.cpp @@ -8,7 +8,6 @@ #include "td/telegram/AccessRights.h" #include "td/telegram/AuthManager.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/ContactsManager.h" #include "td/telegram/DialogId.h" #include "td/telegram/Global.h" @@ -296,7 +295,7 @@ void TopDialogManager::update_rating_e_decay() { if (!is_active_) { return; } - rating_e_decay_ = narrow_cast(G()->shared_config().get_option_integer("rating_e_decay", rating_e_decay_)); + rating_e_decay_ = narrow_cast(G()->get_option_integer("rating_e_decay", rating_e_decay_)); } template @@ -463,11 +462,11 @@ void TopDialogManager::on_get_top_peers(Resultshared_config().set_option_boolean("disable_top_chats", true); + G()->set_option_boolean("disable_top_chats", true); set_is_enabled(false); // apply immediately break; 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 auto top_peers = move_tl_object_as(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_enabled_ = !G()->shared_config().get_option_boolean("disable_top_chats"); + is_enabled_ = !G()->get_option_boolean("disable_top_chats"); update_rating_e_decay(); string need_update_top_peers = G()->td_db()->get_binlog_pmc()->get("top_peers_enabled"); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 47b40d599..461eaf505 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -14,7 +14,6 @@ #include "td/telegram/ChannelId.h" #include "td/telegram/ChatId.h" #include "td/telegram/ConfigManager.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/ContactsManager.h" #include "td/telegram/DialogAction.h" #include "td/telegram/DialogId.h" @@ -1553,7 +1552,7 @@ void UpdatesManager::on_get_difference(tl_object_ptrshared_config().get_option_integer("session_count") <= 1) { + if (G()->get_option_integer("session_count") <= 1) { LOG(ERROR) << "Receive differenceTooLong"; } // TODO @@ -2261,8 +2260,8 @@ void UpdatesManager::add_pending_pts_update(tl_object_ptr if (old_pts > new_pts - pts_count) { 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 " - << source << " = " << oneline(to_string(update)); + << "). Logged in " << G()->get_option_integer("authorization_date") << ". Update from " << source + << " = " << oneline(to_string(update)); postpone_pts_update(std::move(update), new_pts, pts_count, receive_time, std::move(promise)); set_pts_gap_timeout(0.001); return; @@ -2276,9 +2275,8 @@ void UpdatesManager::add_pending_pts_update(tl_object_ptr if (old_pts > accumulated_pts_ - accumulated_pts_count_) { LOG(WARNING) << "Have old_pts (= " << old_pts << ") + accumulated_pts_count (= " << accumulated_pts_count_ << ") > accumulated_pts (= " << accumulated_pts_ << "). new_pts = " << new_pts - << ", pts_count = " << pts_count << ". Logged in " - << G()->shared_config().get_option_integer("authorization_date") << ". Update from " << source << " = " - << oneline(to_string(update)); + << ", pts_count = " << pts_count << ". Logged in " << G()->get_option_integer("authorization_date") + << ". Update from " << source << " = " << oneline(to_string(update)); postpone_pts_update(std::move(update), new_pts, pts_count, receive_time, std::move(promise)); set_pts_gap_timeout(0.001); return; diff --git a/td/telegram/files/FileGcParameters.cpp b/td/telegram/files/FileGcParameters.cpp index 1fb8cef5f..b541fe59e 100644 --- a/td/telegram/files/FileGcParameters.cpp +++ b/td/telegram/files/FileGcParameters.cpp @@ -6,7 +6,6 @@ // #include "td/telegram/files/FileGcParameters.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/Global.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)) , exclude_owner_dialog_ids_(std::move(exclude_owner_dialog_ids)) , dialog_limit_(dialog_limit) { - auto &config = G()->shared_config(); - max_files_size_ = size >= 0 ? size : config.get_option_integer("storage_max_files_size", 100 << 10) << 10; + max_files_size_ = size >= 0 ? size : G()->get_option_integer("storage_max_files_size", 100 << 10) << 10; max_time_from_last_access_ = - ttl >= 0 ? ttl : narrow_cast(config.get_option_integer("storage_max_time_from_last_access", 60 * 60 * 23)); + ttl >= 0 ? ttl : narrow_cast(G()->get_option_integer("storage_max_time_from_last_access", 60 * 60 * 23)); - max_file_count_ = count >= 0 ? count : narrow_cast(config.get_option_integer("storage_max_file_count", 40000)); + max_file_count_ = count >= 0 ? count : narrow_cast(G()->get_option_integer("storage_max_file_count", 40000)); immunity_delay_ = immunity_delay >= 0 ? immunity_delay - : narrow_cast(config.get_option_integer("storage_immunity_delay", 60 * 60)); + : narrow_cast(G()->get_option_integer("storage_immunity_delay", 60 * 60)); } StringBuilder &operator<<(StringBuilder &string_builder, const FileGcParameters ¶meters) { diff --git a/td/telegram/files/FileLoadManager.cpp b/td/telegram/files/FileLoadManager.cpp index ff291a1d9..e7656d2d1 100644 --- a/td/telegram/files/FileLoadManager.cpp +++ b/td/telegram/files/FileLoadManager.cpp @@ -6,7 +6,6 @@ // #include "td/telegram/files/FileLoadManager.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/Global.h" #include "td/telegram/net/DcId.h" #include "td/telegram/TdParameters.h" @@ -29,7 +28,7 @@ void FileLoadManager::start_up() { !G()->parameters().use_file_db /*tdlib_engine*/ ? ResourceManager::Mode::Greedy : ResourceManager::Mode::Baseline); - if (G()->shared_config().get_option_boolean("is_premium")) { + if (G()->get_option_boolean("is_premium")) { max_download_resource_limit_ *= 8; } } diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 593532266..4b958b947 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -6,7 +6,6 @@ // #include "td/telegram/files/FileManager.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/DownloadManager.h" #include "td/telegram/FileReferenceManager.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"); } 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 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) { - if (G()->shared_config().get_option_boolean("ignore_inline_thumbnails")) { + if (G()->get_option_boolean("ignore_inline_thumbnails")) { return false; } @@ -3168,7 +3167,7 @@ Result FileManager::get_input_file_id(FileType type, const tl_object_ptr return FileId(); } 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); 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_); diff --git a/td/telegram/net/ConnectionCreator.cpp b/td/telegram/net/ConnectionCreator.cpp index 9ca56b401..e24984cfa 100644 --- a/td/telegram/net/ConnectionCreator.cpp +++ b/td/telegram/net/ConnectionCreator.cpp @@ -7,7 +7,6 @@ #include "td/telegram/net/ConnectionCreator.h" #include "td/telegram/ConfigManager.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/Global.h" #include "td/telegram/logevent/LogEvent.h" #include "td/telegram/MessagesManager.h" @@ -234,7 +233,7 @@ void ConnectionCreator::get_proxy_link(int32 proxy_id, Promise promise) } 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; switch (proxy.type()) { case Proxy::Type::Socks5: @@ -269,7 +268,7 @@ void ConnectionCreator::get_proxy_link(int32 proxy_id, Promise promise) } ActorId 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()) { VLOG(connections) << "Init block bypass DNS resolver"; GetHostByNameActor::Options options; @@ -297,7 +296,7 @@ void ConnectionCreator::ping_proxy(int32 proxy_id, Promise promise) { CHECK(!close_flag_); if (proxy_id == 0) { 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); if (infos.empty()) { 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 promise) { return promise.set_error(Status::Error(400, "Unknown proxy identifier")); } 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, PromiseCreator::lambda([actor_id = actor_id(this), promise = std::move(promise), proxy_id](Result 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) { active_proxy_id_ = proxy_id; if (proxy_id == 0) { - G()->shared_config().set_option_empty("enabled_proxy_id"); + G()->set_option_empty("enabled_proxy_id"); } 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 (proxy_id == 0) { @@ -701,8 +700,7 @@ Result ConnectionCreator::get_transport_type(const Proxy Result ConnectionCreator::find_connection(const Proxy &proxy, const IPAddress &proxy_ip_address, DcId dc_id, bool allow_media_only, FindConnectionExtra &extra) { extra.debug_str = PSTRING() << "Failed to find valid IP address for " << dc_id; - bool prefer_ipv6 = - G()->shared_config().get_option_boolean("prefer_ipv6") || (proxy.use_proxy() && proxy_ip_address.is_ipv6()); + bool prefer_ipv6 = G()->get_option_boolean("prefer_ipv6") || (proxy.use_proxy() && proxy_ip_address.is_ipv6()); bool only_http = proxy.use_http_caching_proxy(); #if TD_DARWIN_WATCH_OS only_http = true; @@ -1281,7 +1279,7 @@ void ConnectionCreator::loop() { if (resolve_proxy_query_token_ == 0) { resolve_proxy_query_token_ = next_token(); 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(); send_closure( get_dns_resolver(), &GetHostByNameActor::run, proxy.server().str(), proxy.port(), prefer_ipv6, diff --git a/td/telegram/net/NetQueryDispatcher.cpp b/td/telegram/net/NetQueryDispatcher.cpp index e94845e72..41492d555 100644 --- a/td/telegram/net/NetQueryDispatcher.cpp +++ b/td/telegram/net/NetQueryDispatcher.cpp @@ -6,7 +6,6 @@ // #include "td/telegram/net/NetQueryDispatcher.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/Global.h" #include "td/telegram/net/AuthDataShared.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()); 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")); return complete_net_query(std::move(net_query)); // 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(); 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 download_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() { - return max(narrow_cast(G()->shared_config().get_option_integer("session_count")), 1); + return max(narrow_cast(G()->get_option_integer("session_count")), 1); } 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()> &create_reference) { diff --git a/td/telegram/net/NetStatsManager.cpp b/td/telegram/net/NetStatsManager.cpp index daa9515c9..7fbb93149 100644 --- a/td/telegram/net/NetStatsManager.cpp +++ b/td/telegram/net/NetStatsManager.cpp @@ -6,7 +6,6 @@ // #include "td/telegram/net/NetStatsManager.h" -#include "td/telegram/ConfigShared.h" #include "td/telegram/Global.h" #include "td/telegram/logevent/LogEvent.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"); if (!since_str.empty()) { auto since = to_integer(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) { since_total_ = unix_time; 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) { - if (G()->shared_config().get_option_boolean("disable_persistent_network_statistics")) { + if (G()->get_option_boolean("disable_persistent_network_statistics")) { return; }