diff --git a/td/telegram/OptionManager.cpp b/td/telegram/OptionManager.cpp index b657d9ac6..bcefbfc48 100644 --- a/td/telegram/OptionManager.cpp +++ b/td/telegram/OptionManager.cpp @@ -623,10 +623,10 @@ void OptionManager::set_option(const string &name, td_api::object_ptr(value.get())->value_; + td_->set_is_online(is_online); if (!is_bot) { send_closure(td_->state_manager_, &StateManager::on_online, is_online); } - td_->set_is_online(is_online); return promise.set_value(Unit()); } break; diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 64f0a83f3..f2dfde5e1 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -183,6 +183,24 @@ void UpdatesManager::tear_down() { LOG(DEBUG) << "Have " << being_processed_updates_ << " unprocessed updates to apply"; } +void UpdatesManager::start_up() { + class StateCallback final : public StateManager::Callback { + public: + explicit StateCallback(ActorId parent) : parent_(std::move(parent)) { + } + bool on_online(bool is_online) final { + if (is_online) { + send_closure(parent_, &UpdatesManager::try_reload_data); + } + return parent_.is_alive(); + } + + private: + ActorId parent_; + }; + send_closure(G()->state_manager(), &StateManager::add_callback, make_unique(actor_id(this))); +} + void UpdatesManager::hangup_shared() { ref_cnt_--; if (ref_cnt_ == 0) { diff --git a/td/telegram/UpdatesManager.h b/td/telegram/UpdatesManager.h index f7355ec86..85b64c543 100644 --- a/td/telegram/UpdatesManager.h +++ b/td/telegram/UpdatesManager.h @@ -227,6 +227,8 @@ class UpdatesManager final : public Actor { int32 min_postponed_update_pts_ = 0; int32 min_postponed_update_qts_ = 0; + void start_up() final; + void tear_down() final; void hangup_shared() final;