Allow direct access to TopDialogManager.

This commit is contained in:
levlam 2021-09-24 23:17:38 +03:00
parent b9303bf13c
commit 5091aa68e3
6 changed files with 41 additions and 28 deletions

View File

@ -784,7 +784,7 @@ void AuthManager::on_get_authorization(tl_object_ptr<telegram_api::auth_Authoriz
td->notification_manager_->init();
td->stickers_manager_->init();
td->theme_manager_->init();
send_closure(td->top_dialog_manager_, &TopDialogManager::do_start_up);
td->top_dialog_manager_->init();
td->updates_manager_->get_difference("on_get_authorization");
td->on_online_updated(false, true);
if (!is_bot()) {

View File

@ -3435,12 +3435,12 @@ void Td::on_config_option_updated(const string &name) {
} else if (name == "use_storage_optimizer") {
send_closure(storage_manager_, &StorageManager::update_use_storage_optimizer);
} else if (name == "rating_e_decay") {
return send_closure(top_dialog_manager_, &TopDialogManager::update_rating_e_decay);
return send_closure(top_dialog_manager_actor_, &TopDialogManager::update_rating_e_decay);
} else if (name == "disable_contact_registered_notifications") {
send_closure(notification_manager_actor_,
&NotificationManager::on_disable_contact_registered_notifications_changed);
} else if (name == "disable_top_chats") {
send_closure(top_dialog_manager_, &TopDialogManager::update_is_enabled,
send_closure(top_dialog_manager_actor_, &TopDialogManager::update_is_enabled,
!G()->shared_config().get_option_boolean(name));
} else if (name == "connection_parameters") {
if (G()->mtproto_header().set_parameters(G()->shared_config().get_option_string(name))) {
@ -3612,6 +3612,8 @@ void Td::dec_actor_refcnt() {
LOG(DEBUG) << "StickersManager was cleared" << timer;
theme_manager_.reset();
LOG(DEBUG) << "ThemeManager was cleared" << timer;
top_dialog_manager_.reset();
LOG(DEBUG) << "TopDialogManager was cleared" << timer;
updates_manager_.reset();
LOG(DEBUG) << "UpdatesManager was cleared" << timer;
video_notes_manager_.reset();
@ -3761,8 +3763,6 @@ void Td::clear() {
LOG(DEBUG) << "SecretChatsManager was cleared" << timer;
storage_manager_.reset();
LOG(DEBUG) << "StorageManager was cleared" << timer;
top_dialog_manager_.reset();
LOG(DEBUG) << "TopDialogManager was cleared" << timer;
verify_phone_number_manager_.reset();
LOG(DEBUG) << "VerifyPhoneNumberManager was cleared" << timer;
@ -3806,6 +3806,8 @@ void Td::clear() {
LOG(DEBUG) << "StickersManager actor was cleared" << timer;
theme_manager_actor_.reset();
LOG(DEBUG) << "ThemeManager actor was cleared" << timer;
top_dialog_manager_actor_.reset();
LOG(DEBUG) << "TopDialogManager actor was cleared" << timer;
updates_manager_actor_.reset();
LOG(DEBUG) << "UpdatesManager actor was cleared" << timer;
web_pages_manager_actor_.reset();
@ -4266,6 +4268,9 @@ void Td::init_managers() {
theme_manager_ = make_unique<ThemeManager>(this, create_reference());
theme_manager_actor_ = register_actor("ThemeManager", theme_manager_.get());
G()->set_theme_manager(theme_manager_actor_.get());
top_dialog_manager_ = make_unique<TopDialogManager>(this, create_reference());
top_dialog_manager_actor_ = register_actor("TopDialogManager", top_dialog_manager_.get());
G()->set_top_dialog_manager(top_dialog_manager_actor_.get());
updates_manager_ = make_unique<UpdatesManager>(this, create_reference());
updates_manager_actor_ = register_actor("UpdatesManager", updates_manager_.get());
G()->set_updates_manager(updates_manager_actor_.get());
@ -4289,8 +4294,6 @@ void Td::init_managers() {
secret_chats_manager_ = create_actor<SecretChatsManager>("SecretChatsManager", create_reference());
G()->set_secret_chats_manager(secret_chats_manager_.get());
secure_manager_ = create_actor<SecureManager>("SecureManager", create_reference());
top_dialog_manager_ = create_actor<TopDialogManager>("TopDialogManager", create_reference());
G()->set_top_dialog_manager(top_dialog_manager_.get());
verify_phone_number_manager_ = create_actor<PhoneNumberManager>(
"VerifyPhoneNumberManager", PhoneNumberManager::Type::VerifyPhone, create_reference());
}
@ -5214,8 +5217,8 @@ void Td::on_request(uint64 id, td_api::getTopChats &request) {
promise.set_value(MessagesManager::get_chats_object(-1, result.ok()));
}
});
send_closure(top_dialog_manager_, &TopDialogManager::get_top_dialogs, get_top_dialog_category(*request.category_),
narrow_cast<size_t>(request.limit_), std::move(query_promise));
top_dialog_manager_->get_top_dialogs(get_top_dialog_category(*request.category_), narrow_cast<size_t>(request.limit_),
std::move(query_promise));
}
void Td::on_request(uint64 id, const td_api::removeTopChat &request) {
@ -5228,8 +5231,8 @@ void Td::on_request(uint64 id, const td_api::removeTopChat &request) {
if (!dialog_id.is_valid()) {
return send_error_raw(id, 400, "Invalid chat identifier");
}
send_closure(top_dialog_manager_, &TopDialogManager::remove_dialog, get_top_dialog_category(*request.category_),
dialog_id, messages_manager_->get_input_peer(dialog_id, AccessRights::Read));
top_dialog_manager_->remove_dialog(get_top_dialog_category(*request.category_), dialog_id,
messages_manager_->get_input_peer(dialog_id, AccessRights::Read));
send_closure(actor_id(this), &Td::send_result, id, td_api::make_object<td_api::ok>());
}

View File

@ -178,6 +178,8 @@ class Td final : public Actor {
ActorOwn<StickersManager> stickers_manager_actor_;
unique_ptr<ThemeManager> theme_manager_;
ActorOwn<ThemeManager> theme_manager_actor_;
unique_ptr<TopDialogManager> top_dialog_manager_;
ActorOwn<TopDialogManager> top_dialog_manager_actor_;
unique_ptr<UpdatesManager> updates_manager_;
ActorOwn<UpdatesManager> updates_manager_actor_;
unique_ptr<WebPagesManager> web_pages_manager_;
@ -197,7 +199,6 @@ class Td final : public Actor {
ActorOwn<SecretChatsManager> secret_chats_manager_;
ActorOwn<StateManager> state_manager_;
ActorOwn<StorageManager> storage_manager_;
ActorOwn<TopDialogManager> top_dialog_manager_;
ActorOwn<PhoneNumberManager> verify_phone_number_manager_;
class ResultHandler : public std::enable_shared_from_this<ResultHandler> {

View File

@ -108,8 +108,7 @@ static tl_object_ptr<telegram_api::TopPeerCategory> get_top_peer_category(TopDia
}
void TopDialogManager::update_is_enabled(bool is_enabled) {
auto auth_manager = G()->td().get_actor_unsafe()->auth_manager_.get();
if (auth_manager == nullptr || !auth_manager->is_authorized() || auth_manager->is_bot()) {
if (td_->auth_manager_ == nullptr || !td_->auth_manager_->is_authorized() || td_->auth_manager_->is_bot()) {
return;
}
@ -128,7 +127,7 @@ bool TopDialogManager::set_is_enabled(bool is_enabled) {
LOG(DEBUG) << "Change top chats is_enabled to " << is_enabled;
is_enabled_ = is_enabled;
init();
try_start();
return true;
}
@ -512,16 +511,19 @@ void TopDialogManager::do_save_top_dialogs() {
}
void TopDialogManager::start_up() {
do_start_up();
init();
}
void TopDialogManager::do_start_up() {
auto auth_manager = G()->td().get_actor_unsafe()->auth_manager_.get();
if (auth_manager == nullptr || !auth_manager->is_authorized()) {
void TopDialogManager::tear_down() {
parent_.reset();
}
void TopDialogManager::init() {
if (td_->auth_manager_ == nullptr || !td_->auth_manager_->is_authorized()) {
return;
}
is_active_ = G()->parameters().use_chat_info_db && !auth_manager->is_bot();
is_active_ = G()->parameters().use_chat_info_db && !td_->auth_manager_->is_bot();
is_enabled_ = !G()->shared_config().get_option_boolean("disable_top_chats");
update_rating_e_decay();
@ -530,11 +532,11 @@ void TopDialogManager::do_start_up() {
send_toggle_top_peers(need_update_top_peers[0] == '1');
}
init();
try_start();
loop();
}
void TopDialogManager::init() {
void TopDialogManager::try_start() {
was_first_sync_ = false;
first_unsync_change_ = Timestamp();
server_sync_state_ = SyncState::None;
@ -585,9 +587,9 @@ void TopDialogManager::init() {
void TopDialogManager::on_first_sync() {
was_first_sync_ = true;
if (!G()->close_flag() && G()->td().get_actor_unsafe()->auth_manager_->is_bot()) {
if (!G()->close_flag() && td_->auth_manager_->is_bot()) {
is_active_ = false;
init();
try_start();
}
loop();
}

View File

@ -22,12 +22,14 @@
namespace td {
class Td;
class TopDialogManager final : public NetQueryCallback {
public:
explicit TopDialogManager(ActorShared<> parent) : parent_(std::move(parent)) {
TopDialogManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
}
void do_start_up();
void init();
void on_dialog_used(TopDialogCategory category, DialogId dialog_id, int32 date);
@ -44,6 +46,8 @@ class TopDialogManager final : public NetQueryCallback {
static constexpr int32 SERVER_SYNC_DELAY = 86400; // seconds
static constexpr int32 SERVER_SYNC_RESEND_DELAY = 60; // seconds
static constexpr int32 DB_SYNC_DELAY = 5; // seconds
Td *td_;
ActorShared<> parent_;
bool is_active_{false};
@ -108,10 +112,13 @@ class TopDialogManager final : public NetQueryCallback {
void on_result(NetQueryPtr net_query) final;
void init();
void try_start();
void start_up() final;
void loop() final;
void tear_down() final;
};
} // namespace td

View File

@ -2422,7 +2422,7 @@ class CliClient final : public Actor {
td_api::make_object<td_api::addNetworkStatistics>(td_api::make_object<td_api::networkStatisticsEntryFile>(
td_api::make_object<td_api::fileTypeDocument>(), get_network_type(network_type), sent_bytes,
received_bytes)));
} else if (op == "top_chats") {
} else if (op == "gtc") {
send_request(td_api::make_object<td_api::getTopChats>(get_top_chat_category(args), 50));
} else if (op == "rtc") {
string chat_id;