Add Td::set_is_bot_online function.

This commit is contained in:
levlam 2021-03-02 04:06:02 +03:00
parent 1f01a40521
commit dd80b0ef25
3 changed files with 16 additions and 4 deletions

View File

@ -729,7 +729,7 @@ void AuthManager::on_get_authorization(tl_object_ptr<telegram_api::auth_Authoriz
td->schedule_get_promo_data(0);
G()->td_db()->get_binlog_pmc()->set("fetched_marks_as_unread", "1");
} else {
send_closure(G()->state_manager(), &StateManager::on_online, true);
td->set_is_bot_online(true);
}
send_closure(G()->config_manager(), &ConfigManager::request_config);
if (query_id_ != 0) {

View File

@ -3031,7 +3031,7 @@ void Td::on_alarm_timeout(int64 alarm_id) {
updates_manager_->ping_server();
alarm_timeout_.set_timeout_in(PING_SERVER_ALARM_ID,
PING_SERVER_TIMEOUT + Random::fast(0, PING_SERVER_TIMEOUT / 5));
send_closure(G()->state_manager(), &StateManager::on_online, false);
set_is_bot_online(false);
}
return;
}
@ -3190,6 +3190,15 @@ bool Td::is_online() const {
return is_online_;
}
void Td::set_is_bot_online(bool is_bot_online) {
if (is_bot_online == is_bot_online_) {
return;
}
is_bot_online_ = is_bot_online;
send_closure(G()->state_manager(), &StateManager::on_online, is_bot_online_);
}
bool Td::is_authentication_request(int32 id) {
switch (id) {
case td_api::setTdlibParameters::ID:
@ -3538,7 +3547,7 @@ void Td::on_result(NetQueryPtr query) {
if (auth_manager_->is_bot() && auth_manager_->is_authorized()) {
alarm_timeout_.set_timeout_in(PING_SERVER_ALARM_ID,
PING_SERVER_TIMEOUT + Random::fast(0, PING_SERVER_TIMEOUT / 5));
send_closure(G()->state_manager(), &StateManager::on_online, true);
set_is_bot_online(true);
}
}
return;
@ -4177,7 +4186,7 @@ Status Td::init(DbKey key) {
on_online_updated(true, true);
}
if (auth_manager_->is_bot()) {
send_closure(G()->state_manager(), &StateManager::on_online, true);
set_is_bot_online(true);
}
// Send binlog events to managers

View File

@ -124,6 +124,8 @@ class Td final : public NetQueryCallback {
bool is_online() const;
void set_is_bot_online(bool is_bot_online);
template <class ActorT, class... ArgsT>
ActorId<ActorT> create_net_actor(ArgsT &&... args) {
auto slot_id = request_actors_.create(ActorOwn<>(), RequestActorIdType);
@ -287,6 +289,7 @@ class Td final : public NetQueryCallback {
Container<ActorOwn<Actor>> request_actors_;
bool is_online_ = false;
bool is_bot_online_ = false;
NetQueryRef update_status_query_;
int64 alarm_id_ = 1;