Allow direct access to TopDialogManager.
This commit is contained in:
parent
b9303bf13c
commit
5091aa68e3
@ -784,7 +784,7 @@ void AuthManager::on_get_authorization(tl_object_ptr<telegram_api::auth_Authoriz
|
|||||||
td->notification_manager_->init();
|
td->notification_manager_->init();
|
||||||
td->stickers_manager_->init();
|
td->stickers_manager_->init();
|
||||||
td->theme_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->updates_manager_->get_difference("on_get_authorization");
|
||||||
td->on_online_updated(false, true);
|
td->on_online_updated(false, true);
|
||||||
if (!is_bot()) {
|
if (!is_bot()) {
|
||||||
|
@ -3435,12 +3435,12 @@ void Td::on_config_option_updated(const string &name) {
|
|||||||
} else if (name == "use_storage_optimizer") {
|
} else if (name == "use_storage_optimizer") {
|
||||||
send_closure(storage_manager_, &StorageManager::update_use_storage_optimizer);
|
send_closure(storage_manager_, &StorageManager::update_use_storage_optimizer);
|
||||||
} else if (name == "rating_e_decay") {
|
} 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") {
|
} else if (name == "disable_contact_registered_notifications") {
|
||||||
send_closure(notification_manager_actor_,
|
send_closure(notification_manager_actor_,
|
||||||
&NotificationManager::on_disable_contact_registered_notifications_changed);
|
&NotificationManager::on_disable_contact_registered_notifications_changed);
|
||||||
} else if (name == "disable_top_chats") {
|
} 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));
|
!G()->shared_config().get_option_boolean(name));
|
||||||
} else if (name == "connection_parameters") {
|
} else if (name == "connection_parameters") {
|
||||||
if (G()->mtproto_header().set_parameters(G()->shared_config().get_option_string(name))) {
|
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;
|
LOG(DEBUG) << "StickersManager was cleared" << timer;
|
||||||
theme_manager_.reset();
|
theme_manager_.reset();
|
||||||
LOG(DEBUG) << "ThemeManager was cleared" << timer;
|
LOG(DEBUG) << "ThemeManager was cleared" << timer;
|
||||||
|
top_dialog_manager_.reset();
|
||||||
|
LOG(DEBUG) << "TopDialogManager was cleared" << timer;
|
||||||
updates_manager_.reset();
|
updates_manager_.reset();
|
||||||
LOG(DEBUG) << "UpdatesManager was cleared" << timer;
|
LOG(DEBUG) << "UpdatesManager was cleared" << timer;
|
||||||
video_notes_manager_.reset();
|
video_notes_manager_.reset();
|
||||||
@ -3761,8 +3763,6 @@ void Td::clear() {
|
|||||||
LOG(DEBUG) << "SecretChatsManager was cleared" << timer;
|
LOG(DEBUG) << "SecretChatsManager was cleared" << timer;
|
||||||
storage_manager_.reset();
|
storage_manager_.reset();
|
||||||
LOG(DEBUG) << "StorageManager was cleared" << timer;
|
LOG(DEBUG) << "StorageManager was cleared" << timer;
|
||||||
top_dialog_manager_.reset();
|
|
||||||
LOG(DEBUG) << "TopDialogManager was cleared" << timer;
|
|
||||||
verify_phone_number_manager_.reset();
|
verify_phone_number_manager_.reset();
|
||||||
LOG(DEBUG) << "VerifyPhoneNumberManager was cleared" << timer;
|
LOG(DEBUG) << "VerifyPhoneNumberManager was cleared" << timer;
|
||||||
|
|
||||||
@ -3806,6 +3806,8 @@ void Td::clear() {
|
|||||||
LOG(DEBUG) << "StickersManager actor was cleared" << timer;
|
LOG(DEBUG) << "StickersManager actor was cleared" << timer;
|
||||||
theme_manager_actor_.reset();
|
theme_manager_actor_.reset();
|
||||||
LOG(DEBUG) << "ThemeManager actor was cleared" << timer;
|
LOG(DEBUG) << "ThemeManager actor was cleared" << timer;
|
||||||
|
top_dialog_manager_actor_.reset();
|
||||||
|
LOG(DEBUG) << "TopDialogManager actor was cleared" << timer;
|
||||||
updates_manager_actor_.reset();
|
updates_manager_actor_.reset();
|
||||||
LOG(DEBUG) << "UpdatesManager actor was cleared" << timer;
|
LOG(DEBUG) << "UpdatesManager actor was cleared" << timer;
|
||||||
web_pages_manager_actor_.reset();
|
web_pages_manager_actor_.reset();
|
||||||
@ -4266,6 +4268,9 @@ void Td::init_managers() {
|
|||||||
theme_manager_ = make_unique<ThemeManager>(this, create_reference());
|
theme_manager_ = make_unique<ThemeManager>(this, create_reference());
|
||||||
theme_manager_actor_ = register_actor("ThemeManager", theme_manager_.get());
|
theme_manager_actor_ = register_actor("ThemeManager", theme_manager_.get());
|
||||||
G()->set_theme_manager(theme_manager_actor_.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_ = make_unique<UpdatesManager>(this, create_reference());
|
||||||
updates_manager_actor_ = register_actor("UpdatesManager", updates_manager_.get());
|
updates_manager_actor_ = register_actor("UpdatesManager", updates_manager_.get());
|
||||||
G()->set_updates_manager(updates_manager_actor_.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());
|
secret_chats_manager_ = create_actor<SecretChatsManager>("SecretChatsManager", create_reference());
|
||||||
G()->set_secret_chats_manager(secret_chats_manager_.get());
|
G()->set_secret_chats_manager(secret_chats_manager_.get());
|
||||||
secure_manager_ = create_actor<SecureManager>("SecureManager", create_reference());
|
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>(
|
verify_phone_number_manager_ = create_actor<PhoneNumberManager>(
|
||||||
"VerifyPhoneNumberManager", PhoneNumberManager::Type::VerifyPhone, create_reference());
|
"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()));
|
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_),
|
top_dialog_manager_->get_top_dialogs(get_top_dialog_category(*request.category_), narrow_cast<size_t>(request.limit_),
|
||||||
narrow_cast<size_t>(request.limit_), std::move(query_promise));
|
std::move(query_promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, const td_api::removeTopChat &request) {
|
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()) {
|
if (!dialog_id.is_valid()) {
|
||||||
return send_error_raw(id, 400, "Invalid chat identifier");
|
return send_error_raw(id, 400, "Invalid chat identifier");
|
||||||
}
|
}
|
||||||
send_closure(top_dialog_manager_, &TopDialogManager::remove_dialog, get_top_dialog_category(*request.category_),
|
top_dialog_manager_->remove_dialog(get_top_dialog_category(*request.category_), dialog_id,
|
||||||
dialog_id, messages_manager_->get_input_peer(dialog_id, AccessRights::Read));
|
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>());
|
send_closure(actor_id(this), &Td::send_result, id, td_api::make_object<td_api::ok>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,6 +178,8 @@ class Td final : public Actor {
|
|||||||
ActorOwn<StickersManager> stickers_manager_actor_;
|
ActorOwn<StickersManager> stickers_manager_actor_;
|
||||||
unique_ptr<ThemeManager> theme_manager_;
|
unique_ptr<ThemeManager> theme_manager_;
|
||||||
ActorOwn<ThemeManager> theme_manager_actor_;
|
ActorOwn<ThemeManager> theme_manager_actor_;
|
||||||
|
unique_ptr<TopDialogManager> top_dialog_manager_;
|
||||||
|
ActorOwn<TopDialogManager> top_dialog_manager_actor_;
|
||||||
unique_ptr<UpdatesManager> updates_manager_;
|
unique_ptr<UpdatesManager> updates_manager_;
|
||||||
ActorOwn<UpdatesManager> updates_manager_actor_;
|
ActorOwn<UpdatesManager> updates_manager_actor_;
|
||||||
unique_ptr<WebPagesManager> web_pages_manager_;
|
unique_ptr<WebPagesManager> web_pages_manager_;
|
||||||
@ -197,7 +199,6 @@ class Td final : public Actor {
|
|||||||
ActorOwn<SecretChatsManager> secret_chats_manager_;
|
ActorOwn<SecretChatsManager> secret_chats_manager_;
|
||||||
ActorOwn<StateManager> state_manager_;
|
ActorOwn<StateManager> state_manager_;
|
||||||
ActorOwn<StorageManager> storage_manager_;
|
ActorOwn<StorageManager> storage_manager_;
|
||||||
ActorOwn<TopDialogManager> top_dialog_manager_;
|
|
||||||
ActorOwn<PhoneNumberManager> verify_phone_number_manager_;
|
ActorOwn<PhoneNumberManager> verify_phone_number_manager_;
|
||||||
|
|
||||||
class ResultHandler : public std::enable_shared_from_this<ResultHandler> {
|
class ResultHandler : public std::enable_shared_from_this<ResultHandler> {
|
||||||
|
@ -108,8 +108,7 @@ static tl_object_ptr<telegram_api::TopPeerCategory> get_top_peer_category(TopDia
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TopDialogManager::update_is_enabled(bool is_enabled) {
|
void TopDialogManager::update_is_enabled(bool is_enabled) {
|
||||||
auto auth_manager = G()->td().get_actor_unsafe()->auth_manager_.get();
|
if (td_->auth_manager_ == nullptr || !td_->auth_manager_->is_authorized() || td_->auth_manager_->is_bot()) {
|
||||||
if (auth_manager == nullptr || !auth_manager->is_authorized() || auth_manager->is_bot()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +127,7 @@ bool TopDialogManager::set_is_enabled(bool is_enabled) {
|
|||||||
|
|
||||||
LOG(DEBUG) << "Change top chats is_enabled to " << is_enabled;
|
LOG(DEBUG) << "Change top chats is_enabled to " << is_enabled;
|
||||||
is_enabled_ = is_enabled;
|
is_enabled_ = is_enabled;
|
||||||
init();
|
try_start();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -512,16 +511,19 @@ void TopDialogManager::do_save_top_dialogs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TopDialogManager::start_up() {
|
void TopDialogManager::start_up() {
|
||||||
do_start_up();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TopDialogManager::do_start_up() {
|
void TopDialogManager::tear_down() {
|
||||||
auto auth_manager = G()->td().get_actor_unsafe()->auth_manager_.get();
|
parent_.reset();
|
||||||
if (auth_manager == nullptr || !auth_manager->is_authorized()) {
|
}
|
||||||
|
|
||||||
|
void TopDialogManager::init() {
|
||||||
|
if (td_->auth_manager_ == nullptr || !td_->auth_manager_->is_authorized()) {
|
||||||
return;
|
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");
|
is_enabled_ = !G()->shared_config().get_option_boolean("disable_top_chats");
|
||||||
update_rating_e_decay();
|
update_rating_e_decay();
|
||||||
|
|
||||||
@ -530,11 +532,11 @@ void TopDialogManager::do_start_up() {
|
|||||||
send_toggle_top_peers(need_update_top_peers[0] == '1');
|
send_toggle_top_peers(need_update_top_peers[0] == '1');
|
||||||
}
|
}
|
||||||
|
|
||||||
init();
|
try_start();
|
||||||
loop();
|
loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TopDialogManager::init() {
|
void TopDialogManager::try_start() {
|
||||||
was_first_sync_ = false;
|
was_first_sync_ = false;
|
||||||
first_unsync_change_ = Timestamp();
|
first_unsync_change_ = Timestamp();
|
||||||
server_sync_state_ = SyncState::None;
|
server_sync_state_ = SyncState::None;
|
||||||
@ -585,9 +587,9 @@ void TopDialogManager::init() {
|
|||||||
|
|
||||||
void TopDialogManager::on_first_sync() {
|
void TopDialogManager::on_first_sync() {
|
||||||
was_first_sync_ = true;
|
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;
|
is_active_ = false;
|
||||||
init();
|
try_start();
|
||||||
}
|
}
|
||||||
loop();
|
loop();
|
||||||
}
|
}
|
||||||
|
@ -22,12 +22,14 @@
|
|||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
|
class Td;
|
||||||
|
|
||||||
class TopDialogManager final : public NetQueryCallback {
|
class TopDialogManager final : public NetQueryCallback {
|
||||||
public:
|
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);
|
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_DELAY = 86400; // seconds
|
||||||
static constexpr int32 SERVER_SYNC_RESEND_DELAY = 60; // seconds
|
static constexpr int32 SERVER_SYNC_RESEND_DELAY = 60; // seconds
|
||||||
static constexpr int32 DB_SYNC_DELAY = 5; // seconds
|
static constexpr int32 DB_SYNC_DELAY = 5; // seconds
|
||||||
|
|
||||||
|
Td *td_;
|
||||||
ActorShared<> parent_;
|
ActorShared<> parent_;
|
||||||
|
|
||||||
bool is_active_{false};
|
bool is_active_{false};
|
||||||
@ -108,10 +112,13 @@ class TopDialogManager final : public NetQueryCallback {
|
|||||||
|
|
||||||
void on_result(NetQueryPtr net_query) final;
|
void on_result(NetQueryPtr net_query) final;
|
||||||
|
|
||||||
void init();
|
void try_start();
|
||||||
|
|
||||||
void start_up() final;
|
void start_up() final;
|
||||||
|
|
||||||
void loop() final;
|
void loop() final;
|
||||||
|
|
||||||
|
void tear_down() final;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -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::addNetworkStatistics>(td_api::make_object<td_api::networkStatisticsEntryFile>(
|
||||||
td_api::make_object<td_api::fileTypeDocument>(), get_network_type(network_type), sent_bytes,
|
td_api::make_object<td_api::fileTypeDocument>(), get_network_type(network_type), sent_bytes,
|
||||||
received_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));
|
send_request(td_api::make_object<td_api::getTopChats>(get_top_chat_category(args), 50));
|
||||||
} else if (op == "rtc") {
|
} else if (op == "rtc") {
|
||||||
string chat_id;
|
string chat_id;
|
||||||
|
Loading…
Reference in New Issue
Block a user