From b9d73b5c4720b6ac43398d31ef661a74531d106a Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 5 Mar 2019 07:35:17 +0300 Subject: [PATCH] More start_up and bots fixes. GitOrigin-RevId: 1f72829332cea0b863cb7813b490782f0ed39db3 --- td/telegram/AuthManager.cpp | 2 ++ td/telegram/MessagesManager.cpp | 2 +- td/telegram/PollManager.cpp | 2 +- td/telegram/TopDialogManager.cpp | 11 ++++++++++- td/telegram/TopDialogManager.h | 2 ++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/td/telegram/AuthManager.cpp b/td/telegram/AuthManager.cpp index 2eb771559..5d0ef75a5 100644 --- a/td/telegram/AuthManager.cpp +++ b/td/telegram/AuthManager.cpp @@ -22,6 +22,7 @@ #include "td/telegram/PasswordManager.h" #include "td/telegram/Td.h" #include "td/telegram/TdDb.h" +#include "td/telegram/TopDialogManager.h" #include "td/telegram/UniqueId.h" #include "td/telegram/UpdatesManager.h" @@ -562,6 +563,7 @@ void AuthManager::on_authorization(tl_object_ptrshared_config().set_option_integer("session_count", auth->tmp_sessions_); } td->notification_manager_->init(); + send_closure(td->top_dialog_manager_, &TopDialogManager::do_start_up); td->updates_manager_->get_difference("on_authorization"); td->on_online_updated(false, true); td->schedule_get_terms_of_service(0); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index c61949e51..c9d0721e8 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -8998,7 +8998,7 @@ void MessagesManager::init() { channels_notification_settings_.disable_pinned_message_notifications = false; channels_notification_settings_.disable_mention_notifications = false; channels_notification_settings_.is_synchronized = false; - if (!td_->auth_manager_->is_bot()) { + if (td_->auth_manager_->is_authorized() && !td_->auth_manager_->is_bot()) { send_get_scope_notification_settings_query(NotificationSettingsScope::Channel, Promise<>()); } } diff --git a/td/telegram/PollManager.cpp b/td/telegram/PollManager.cpp index 16ea8dcd3..3ac6c0060 100644 --- a/td/telegram/PollManager.cpp +++ b/td/telegram/PollManager.cpp @@ -635,7 +635,7 @@ void PollManager::on_update_poll_timeout(PollId poll_id) { } void PollManager::on_get_poll_results_failed(PollId poll_id) { - if (!get_poll_is_closed(poll_id)) { + if (!get_poll_is_closed(poll_id) && !td_->auth_manager_->is_bot()) { auto timeout = get_polling_timeout(); LOG(INFO) << "Schedule updating of " << poll_id << " in " << timeout; update_poll_timeout_.add_timeout_in(poll_id.get(), timeout); diff --git a/td/telegram/TopDialogManager.cpp b/td/telegram/TopDialogManager.cpp index 6c627b68f..682239aa9 100644 --- a/td/telegram/TopDialogManager.cpp +++ b/td/telegram/TopDialogManager.cpp @@ -464,7 +464,16 @@ void TopDialogManager::do_save_top_dialogs() { } void TopDialogManager::start_up() { - is_active_ = G()->parameters().use_chat_info_db && !G()->td().get_actor_unsafe()->auth_manager_->is_bot(); + do_start_up(); +} + +void TopDialogManager::do_start_up() { + auto auth_manager = G()->td().get_actor_unsafe()->auth_manager_.get(); + if (auth_manager == nullptr || !auth_manager->is_authorized()) { + return; + } + + is_active_ = G()->parameters().use_chat_info_db && !auth_manager->is_bot(); is_enabled_ = !G()->shared_config().get_option_boolean("disable_top_chats"); update_rating_e_decay(); diff --git a/td/telegram/TopDialogManager.h b/td/telegram/TopDialogManager.h index 8838b0af5..1117f1255 100644 --- a/td/telegram/TopDialogManager.h +++ b/td/telegram/TopDialogManager.h @@ -49,6 +49,8 @@ class TopDialogManager : public NetQueryCallback { explicit TopDialogManager(ActorShared<> parent) : parent_(std::move(parent)) { } + void do_start_up(); + void on_dialog_used(TopDialogCategory category, DialogId dialog_id, int32 date); void remove_dialog(TopDialogCategory category, DialogId dialog_id, tl_object_ptr input_peer);