Call on_option_updated only after Td is fully inited.

This commit is contained in:
levlam 2022-08-18 19:12:15 +03:00
parent bece21cc38
commit 29b35f3698
3 changed files with 18 additions and 11 deletions

View File

@ -105,6 +105,10 @@ OptionManager::OptionManager(Td *td)
OptionManager::~OptionManager() = default;
void OptionManager::on_td_inited() {
is_td_inited_ = true;
}
void OptionManager::set_option_boolean(Slice name, bool value) {
set_option(name, value ? Slice("Btrue") : Slice("Bfalse"));
}
@ -178,7 +182,15 @@ void OptionManager::set_option(Slice name, Slice value) {
}
option_pmc_->set(name.str(), value.str());
}
on_option_updated(name);
if (!G()->close_flag() && is_td_inited_) {
on_option_updated(name);
}
if (!is_internal_option(name)) {
send_closure(G()->td(), &Td::send_update,
td_api::make_object<td_api::updateOption>(name.str(), get_option_value_object(get_option(name))));
}
}
string OptionManager::get_option(Slice name) const {
@ -275,9 +287,6 @@ bool OptionManager::is_synchronous_option(Slice name) {
}
void OptionManager::on_option_updated(Slice name) {
if (G()->close_flag()) {
return;
}
switch (name[0]) {
case 'a':
if (name == "animated_emoji_zoom") {
@ -425,13 +434,6 @@ void OptionManager::on_option_updated(Slice name) {
default:
break;
}
if (is_internal_option(name)) {
return;
}
send_closure(G()->td(), &Td::send_update,
td_api::make_object<td_api::updateOption>(name.str(), get_option_value_object(get_option(name))));
}
void OptionManager::get_option(const string &name, Promise<td_api::object_ptr<td_api::OptionValue>> &&promise) {

View File

@ -30,6 +30,8 @@ class OptionManager {
OptionManager &operator=(OptionManager &&) = delete;
~OptionManager();
void on_td_inited();
void set_option_boolean(Slice name, bool value);
void set_option_empty(Slice name);
@ -80,6 +82,7 @@ class OptionManager {
void send_unix_time_update();
Td *td_;
bool is_td_inited_ = false;
unique_ptr<TsSeqKeyValue> options_;
std::shared_ptr<KeyValueSyncInterface> option_pmc_;

View File

@ -3686,6 +3686,8 @@ void Td::init(Result<TdDb::OpenedDatabase> r_opened_database) {
storage_manager_ = create_actor<StorageManager>("StorageManager", create_reference(), G()->get_gc_scheduler_id());
G()->set_storage_manager(storage_manager_.get());
option_manager_->on_td_inited();
VLOG(td_init) << "Send binlog events";
for (auto &event : events.user_events) {
contacts_manager_->on_binlog_user_event(std::move(event));