Use send_closure_later in reload_dialog_filters to avoid accidental Timeout usage.

GitOrigin-RevId: 9d3f29b0d6dac7c1834426c9e07885cbf6cd0bb9
This commit is contained in:
levlam 2020-05-28 12:14:58 +03:00
parent 10402d9f5b
commit 25badecb71
2 changed files with 16 additions and 11 deletions

View File

@ -14238,22 +14238,25 @@ void MessagesManager::schedule_dialog_filters_reload(double timeout) {
timeout = 0.0; timeout = 0.0;
} }
LOG(INFO) << "Schedule reload of dialog filters in " << timeout; LOG(INFO) << "Schedule reload of dialog filters in " << timeout;
reload_dialog_filters_timeout_.set_callback(std::move(MessagesManager::reload_dialog_filters)); reload_dialog_filters_timeout_.set_callback(std::move(MessagesManager::on_reload_dialog_filters_timeout));
reload_dialog_filters_timeout_.set_callback_data(static_cast<void *>(td_)); reload_dialog_filters_timeout_.set_callback_data(static_cast<void *>(this));
reload_dialog_filters_timeout_.set_timeout_in(timeout); reload_dialog_filters_timeout_.set_timeout_in(timeout);
} }
void MessagesManager::reload_dialog_filters(void *td) { void MessagesManager::on_reload_dialog_filters_timeout(void *messages_manager_ptr) {
if (G()->close_flag()) { if (G()->close_flag()) {
return; return;
} }
auto td_ptr = static_cast<Td *>(td); auto messages_manager = static_cast<MessagesManager *>(messages_manager_ptr);
auto messages_manager = td_ptr->messages_manager_.get(); send_closure_later(messages_manager->actor_id(messages_manager), &MessagesManager::reload_dialog_filters);
auto promise = PromiseCreator::lambda([actor_id = messages_manager->actor_id(messages_manager)]( }
Result<vector<tl_object_ptr<telegram_api::dialogFilter>>> r_filters) {
send_closure(actor_id, &MessagesManager::on_get_dialog_filters, std::move(r_filters), false); void MessagesManager::reload_dialog_filters() {
}); auto promise = PromiseCreator::lambda(
td_ptr->create_handler<GetDialogFiltersQuery>(std::move(promise))->send(); [actor_id = actor_id(this)](Result<vector<tl_object_ptr<telegram_api::dialogFilter>>> r_filters) {
send_closure(actor_id, &MessagesManager::on_get_dialog_filters, std::move(r_filters), false);
});
td_->create_handler<GetDialogFiltersQuery>(std::move(promise))->send();
} }
void MessagesManager::on_get_dialog_filters(Result<vector<tl_object_ptr<telegram_api::dialogFilter>>> r_filters, void MessagesManager::on_get_dialog_filters(Result<vector<tl_object_ptr<telegram_api::dialogFilter>>> r_filters,

View File

@ -2232,7 +2232,9 @@ class MessagesManager : public Actor {
void schedule_dialog_filters_reload(double timeout); void schedule_dialog_filters_reload(double timeout);
static void reload_dialog_filters(void *td); static void on_reload_dialog_filters_timeout(void *messages_manager_ptr);
void reload_dialog_filters();
void on_get_dialog_filters(Result<vector<tl_object_ptr<telegram_api::dialogFilter>>> r_filters, bool dummy); void on_get_dialog_filters(Result<vector<tl_object_ptr<telegram_api::dialogFilter>>> r_filters, bool dummy);