From 861f0edab4e053906b09adf0e75c9abcecc782a4 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 12 Oct 2023 22:30:28 +0300 Subject: [PATCH] Replace TopDialogManager.is_active_ with !is_bot(). --- td/telegram/TopDialogManager.cpp | 25 ++++++++++--------------- td/telegram/TopDialogManager.h | 1 - 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/td/telegram/TopDialogManager.cpp b/td/telegram/TopDialogManager.cpp index 5f9b2ccd0..e1c8ff2e0 100644 --- a/td/telegram/TopDialogManager.cpp +++ b/td/telegram/TopDialogManager.cpp @@ -197,7 +197,8 @@ void TopDialogManager::on_toggle_top_peers(bool is_enabled, Result &&resul } void TopDialogManager::on_dialog_used(TopDialogCategory category, DialogId dialog_id, int32 date) { - if (!is_active_ || !is_enabled_) { + CHECK(!td_->auth_manager_->is_bot()); + if (!is_enabled_) { return; } auto pos = static_cast(category); @@ -240,7 +241,8 @@ void TopDialogManager::remove_dialog(TopDialogCategory category, DialogId dialog if (!td_->messages_manager_->have_dialog_force(dialog_id, "remove_dialog")) { return promise.set_error(Status::Error(400, "Chat not found")); } - if (!is_active_ || !is_enabled_) { + CHECK(!td_->auth_manager_->is_bot()); + if (!is_enabled_) { return promise.set_value(Unit()); } @@ -293,9 +295,7 @@ int TopDialogManager::is_top_dialog(TopDialogCategory category, size_t limit, Di CHECK(category != TopDialogCategory::Size); CHECK(category != TopDialogCategory::ForwardUsers); CHECK(limit > 0); - if (!is_active_) { - return -1; - } + CHECK(!td_->auth_manager_->is_bot()); if (!is_enabled_) { return 0; } @@ -313,7 +313,7 @@ int TopDialogManager::is_top_dialog(TopDialogCategory category, size_t limit, Di } void TopDialogManager::update_rating_e_decay() { - if (!is_active_) { + if (td_->auth_manager_->is_bot()) { return; } rating_e_decay_ = narrow_cast(G()->get_option_integer("rating_e_decay", rating_e_decay_)); @@ -554,7 +554,6 @@ void TopDialogManager::init() { return; } - is_active_ = !td_->auth_manager_->is_bot(); is_enabled_ = !G()->get_option_boolean("disable_top_chats"); update_rating_e_decay(); @@ -573,12 +572,12 @@ void TopDialogManager::try_start() { server_sync_state_ = SyncState::None; last_server_sync_ = Timestamp(); - LOG(DEBUG) << "Init is enabled: " << is_enabled_; - if (!is_active_) { - G()->td_db()->get_binlog_pmc()->erase_by_prefix("top_dialogs"); + if (td_->auth_manager_->is_bot()) { return; } + LOG(DEBUG) << "Init is enabled: " << is_enabled_; + auto di_top_dialogs_ts = G()->td_db()->get_binlog_pmc()->get("top_dialogs_ts"); if (!di_top_dialogs_ts.empty()) { last_server_sync_ = Timestamp::in(to_integer(di_top_dialogs_ts) - Clocks::system()); @@ -616,15 +615,11 @@ void TopDialogManager::try_start() { void TopDialogManager::on_first_sync() { was_first_sync_ = true; - if (!G()->close_flag() && td_->auth_manager_->is_bot()) { - is_active_ = false; - try_start(); - } loop(); } void TopDialogManager::loop() { - if (!is_active_ || G()->close_flag()) { + if (td_->auth_manager_->is_bot() || G()->close_flag()) { return; } diff --git a/td/telegram/TopDialogManager.h b/td/telegram/TopDialogManager.h index b9513ee28..51a7b16eb 100644 --- a/td/telegram/TopDialogManager.h +++ b/td/telegram/TopDialogManager.h @@ -52,7 +52,6 @@ class TopDialogManager final : public Actor { Td *td_; ActorShared<> parent_; - bool is_active_ = false; bool is_enabled_ = true; bool is_synchronized_ = false; int32 rating_e_decay_ = 241920;