diff --git a/td/telegram/ConfigShared.cpp b/td/telegram/ConfigShared.cpp index 457a8c8d0..59378fe66 100644 --- a/td/telegram/ConfigShared.cpp +++ b/td/telegram/ConfigShared.cpp @@ -101,10 +101,6 @@ string ConfigShared::get_option_string(Slice name, string default_value) const { return str_value.substr(1); } -tl_object_ptr ConfigShared::get_option_value(Slice name) const { - return get_option_value_object(get_option(name)); -} - bool ConfigShared::set_option(Slice name, Slice value) { if (value.empty()) { return config_pmc_->erase(name.str()) != 0; @@ -113,29 +109,6 @@ bool ConfigShared::set_option(Slice name, Slice value) { } } -tl_object_ptr ConfigShared::get_option_value_object(Slice value) { - if (value.empty()) { - return make_tl_object(); - } - - switch (value[0]) { - case 'B': - if (value == "Btrue") { - return make_tl_object(true); - } - if (value == "Bfalse") { - return make_tl_object(false); - } - break; - case 'I': - return make_tl_object(to_integer(value.substr(1))); - case 'S': - return make_tl_object(value.substr(1).str()); - } - - return make_tl_object(value.str()); -} - void ConfigShared::on_option_updated(Slice name) const { if (callback_ != nullptr) { callback_->on_option_updated(name.str(), get_option(name)); diff --git a/td/telegram/ConfigShared.h b/td/telegram/ConfigShared.h index 1cb5682fd..b74e4f845 100644 --- a/td/telegram/ConfigShared.h +++ b/td/telegram/ConfigShared.h @@ -6,8 +6,6 @@ // #pragma once -#include "td/telegram/td_api.h" - #include "td/db/KeyValueSyncInterface.h" #include "td/utils/common.h" @@ -41,24 +39,21 @@ class ConfigShared { 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; - tl_object_ptr get_option_value(Slice name) const; - - static tl_object_ptr get_option_value_object(Slice value); - private: std::shared_ptr config_pmc_; unique_ptr callback_; bool set_option(Slice name, Slice value); - string get_option(Slice name) const; - void on_option_updated(Slice name) const; }; diff --git a/td/telegram/OptionManager.cpp b/td/telegram/OptionManager.cpp index fd53fb569..71b51cf39 100644 --- a/td/telegram/OptionManager.cpp +++ b/td/telegram/OptionManager.cpp @@ -63,7 +63,7 @@ void OptionManager::on_update_server_time_difference() { } void OptionManager::clear_options() { - for (auto &option : G()->shared_config().get_options()) { + for (const auto &option : G()->shared_config().get_options()) { if (!is_internal_option(option.first)) { send_closure( G()->td(), &Td::send_update, @@ -272,7 +272,8 @@ void OptionManager::on_option_updated(const string &name) { } // send_closure was already used in the callback - td_->send_update(td_api::make_object(name, G()->shared_config().get_option_value(name))); + td_->send_update( + td_api::make_object(name, get_option_value_object(G()->shared_config().get_option(name)))); } void OptionManager::get_option(const string &name, Promise> &&promise) { @@ -280,7 +281,7 @@ void OptionManager::get_option(const string &name, Promiseshared_config().get_option_value(name)); + promise.set_value(get_option_value_object(G()->shared_config().get_option(name))); }); }; switch (name[0]) { @@ -623,6 +624,29 @@ void OptionManager::set_option(const string &name, td_api::object_ptr OptionManager::get_option_value_object(Slice value) { + if (value.empty()) { + return td_api::make_object(); + } + + switch (value[0]) { + case 'B': + if (value == "Btrue") { + return td_api::make_object(true); + } + if (value == "Bfalse") { + return td_api::make_object(false); + } + break; + case 'I': + return td_api::make_object(to_integer(value.substr(1))); + case 'S': + return td_api::make_object(value.substr(1).str()); + } + + return td_api::make_object(value.str()); +} + void OptionManager::get_current_state(vector> &updates) const { updates.push_back(td_api::make_object( "version", td_api::make_object(Td::TDLIB_VERSION))); @@ -634,8 +658,8 @@ void OptionManager::get_current_state(vector> for (const auto &option : G()->shared_config().get_options()) { if (!is_internal_option(option.first)) { - updates.push_back(td_api::make_object( - option.first, ConfigShared::get_option_value_object(option.second))); + updates.push_back( + td_api::make_object(option.first, get_option_value_object(option.second))); } } } diff --git a/td/telegram/OptionManager.h b/td/telegram/OptionManager.h index 4dbbec97e..b975ce778 100644 --- a/td/telegram/OptionManager.h +++ b/td/telegram/OptionManager.h @@ -47,6 +47,8 @@ class OptionManager final : public Actor { static td_api::object_ptr get_unix_time_option_value_object(); + static td_api::object_ptr get_option_value_object(Slice value); + void send_unix_time_update(); Td *td_;