From 011d5c123a233dafd93af835ab5c1a8b1a630b85 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Fri, 2 Oct 2020 17:32:24 +0200 Subject: [PATCH] Rename chat_unload_delay and fix its implementation --- td/telegram/MessagesManager.cpp | 11 ++++++++--- td/telegram/Td.cpp | 8 +++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 42bcd0024..81e85ab04 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -10238,14 +10238,19 @@ void MessagesManager::delete_all_channel_messages_from_user_on_server(ChannelId int32 MessagesManager::get_unload_dialog_delay() const { constexpr int32 DIALOG_UNLOAD_DELAY = 60; // seconds constexpr int32 DIALOG_UNLOAD_BOT_DELAY = 1800; // seconds - auto default_value = td_->auth_manager_->is_bot() ? DIALOG_UNLOAD_BOT_DELAY : DIALOG_UNLOAD_DELAY; - return narrow_cast(G()->shared_config().get_option_integer("chat_unload_delay", default_value)); + CHECK(is_message_unload_enabled()); + auto default_unload_delay = td_->auth_manager_->is_bot() ? DIALOG_UNLOAD_BOT_DELAY : DIALOG_UNLOAD_DELAY; + return narrow_cast(G()->shared_config().get_option_integer("message_unload_delay", default_unload_delay)); } void MessagesManager::unload_dialog(DialogId dialog_id) { if (G()->close_flag()) { return; } + if (!is_message_unload_enabled()) { + // just in case + return; + } Dialog *d = get_dialog(dialog_id); CHECK(d != nullptr); @@ -13904,7 +13909,7 @@ void MessagesManager::dump_debug_message_op(const Dialog *d, int priority) { } bool MessagesManager::is_message_unload_enabled() const { - auto has_custom_unload_time = G()->shared_config().have_option("chat_unload_delay"); + auto has_custom_unload_time = G()->shared_config().have_option("message_unload_delay"); return G()->parameters().use_message_db || td_->auth_manager_->is_bot() || has_custom_unload_time; } diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index b694bc4b0..366e7982b 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -7142,9 +7142,6 @@ void Td::on_request(uint64 id, td_api::setOption &request) { } break; case 'd': - if (set_integer_option("dialog_unload_delay")) { - return; - } if (!is_bot && set_boolean_option("disable_contact_registered_notifications")) { return; } @@ -7251,6 +7248,11 @@ void Td::on_request(uint64 id, td_api::setOption &request) { return; } break; + case 'm': + if (set_integer_option("message_unload_delay", 60, 86400)) { + return; + } + break; case 'n': if (!is_bot && set_integer_option("notification_group_count_max", NotificationManager::MIN_NOTIFICATION_GROUP_COUNT_MAX,