From c53eaf92a7a52b46abe264c8f5acf52188656c38 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 16 Nov 2018 01:03:04 +0300 Subject: [PATCH] Support notification related options. GitOrigin-RevId: f6e5574fe1466f779995fb3e2914fa48ba844ffe --- td/telegram/ConfigManager.cpp | 12 ++++++----- td/telegram/NotificationManager.cpp | 33 +++++++++++++++++++++++------ td/telegram/NotificationManager.h | 6 ++++++ td/telegram/Td.cpp | 8 +++++++ 4 files changed, 48 insertions(+), 11 deletions(-) diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index 8ca0c84c4..8cb135cf4 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -854,8 +854,13 @@ void ConfigManager::process_config(tl_object_ptr config) { shared_config.set_option_string("photo_search_bot_username", config->img_search_username_); } - shared_config.set_option_integer("online_update_period_ms", config->online_update_period_ms_); - shared_config.set_option_integer("online_cloud_timeout_ms", config->online_cloud_timeout_ms_); + auto fix_timeout_ms = [](int32 timeout_ms) { return clamp(timeout_ms, 1000, 86400 * 1000); }; + + shared_config.set_option_integer("online_update_period_ms", fix_timeout_ms(config->online_update_period_ms_)); + + shared_config.set_option_integer("online_cloud_timeout_ms", fix_timeout_ms(config->online_cloud_timeout_ms_)); + shared_config.set_option_integer("notification_cloud_delay_ms", fix_timeout_ms(config->notify_cloud_delay_ms_)); + shared_config.set_option_integer("notification_default_delay_ms", fix_timeout_ms(config->notify_default_delay_ms_)); // delete outdated options shared_config.set_option_empty("suggested_language_code"); @@ -884,9 +889,6 @@ void ConfigManager::process_config(tl_object_ptr config) { // shared_config.set_option_integer("offline_blur_timeout_ms", config->offline_blur_timeout_ms_); // shared_config.set_option_integer("offline_idle_timeout_ms", config->offline_idle_timeout_ms_); - // shared_config.set_option_integer("notify_cloud_delay_ms", config->notify_cloud_delay_ms_); - // shared_config.set_option_integer("notify_default_delay_ms", config->notify_default_delay_ms_); - // shared_config.set_option_integer("push_chat_period_ms", config->push_chat_period_ms_); // shared_config.set_option_integer("push_chat_limit", config->push_chat_limit_); } diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index e4daf1d0e..fe658cec9 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -53,12 +53,9 @@ void NotificationManager::start_up() { on_notification_group_count_max_changed(); on_notification_group_size_max_changed(); - online_cloud_timeout_ms_ = - G()->shared_config().get_option_integer("online_cloud_timeout_ms", DEFAULT_ONLINE_CLOUD_TIMEOUT_MS); - notification_cloud_delay_ms_ = - G()->shared_config().get_option_integer("notification_cloud_delay_ms", DEFAULT_ONLINE_CLOUD_DELAY_MS); - notification_default_delay_ms_ = - G()->shared_config().get_option_integer("notification_default_delay_ms", DEFAULT_DEFAULT_DELAY_MS); + on_online_cloud_timeout_changed(); + on_notification_cloud_delay_changed(); + on_notification_default_delay_changed(); // TODO load groups } @@ -428,6 +425,9 @@ void NotificationManager::on_notification_group_count_max_changed() { return; } + VLOG(notifications) << "Change max notification group count from " << max_notification_group_count_ << " to " + << new_max_notification_group_count; + if (max_notification_group_count_ != 0) { // TODO } @@ -449,6 +449,9 @@ void NotificationManager::on_notification_group_size_max_changed() { return; } + VLOG(notifications) << "Change max notification group size from " << max_notification_group_size_ << " to " + << new_max_notification_group_size; + if (max_notification_group_size_ != 0) { // TODO } @@ -458,4 +461,22 @@ void NotificationManager::on_notification_group_size_max_changed() { max_notification_group_size_ + max(EXTRA_GROUP_SIZE / 2, min(max_notification_group_size_, EXTRA_GROUP_SIZE)); } +void NotificationManager::on_online_cloud_timeout_changed() { + online_cloud_timeout_ms_ = + G()->shared_config().get_option_integer("online_cloud_timeout_ms", DEFAULT_ONLINE_CLOUD_TIMEOUT_MS); + VLOG(notifications) << "Set online_cloud_timeout_ms to " << online_cloud_timeout_ms_; +} + +void NotificationManager::on_notification_cloud_delay_changed() { + notification_cloud_delay_ms_ = + G()->shared_config().get_option_integer("notification_cloud_delay_ms", DEFAULT_ONLINE_CLOUD_DELAY_MS); + VLOG(notifications) << "Set notification_cloud_delay_ms to " << notification_cloud_delay_ms_; +} + +void NotificationManager::on_notification_default_delay_changed() { + notification_default_delay_ms_ = + G()->shared_config().get_option_integer("notification_default_delay_ms", DEFAULT_DEFAULT_DELAY_MS); + VLOG(notifications) << "Set notification_default_delay_ms to " << notification_default_delay_ms_; +} + } // namespace td diff --git a/td/telegram/NotificationManager.h b/td/telegram/NotificationManager.h index bb9500497..95d6d2091 100644 --- a/td/telegram/NotificationManager.h +++ b/td/telegram/NotificationManager.h @@ -57,6 +57,12 @@ class NotificationManager : public Actor { void on_notification_group_size_max_changed(); + void on_online_cloud_timeout_changed(); + + void on_notification_cloud_delay_changed(); + + void on_notification_default_delay_changed(); + private: static constexpr int32 DEFAULT_GROUP_COUNT_MAX = 10; static constexpr int32 DEFAULT_GROUP_SIZE_MAX = 10; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 0292ecf1c..15a40629d 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3426,6 +3426,8 @@ bool Td::is_internal_config_option(Slice name) { return name == "language_pack_version"; case 'm': return name == "my_phone_number"; + case 'n': + return name == "notification_cloud_delay_ms" || name == "notification_default_delay_ms"; case 'o': return name == "online_update_period_ms" || name == "online_cloud_timeout_ms"; case 'r': @@ -3489,6 +3491,12 @@ void Td::on_config_option_updated(const string &name) { send_closure(notification_manager_actor_, &NotificationManager::on_notification_group_count_max_changed); } else if (name == "notification_group_size_max") { send_closure(notification_manager_actor_, &NotificationManager::on_notification_group_size_max_changed); + } else if (name == "online_cloud_timeout_ms") { + return send_closure(notification_manager_actor_, &NotificationManager::on_online_cloud_timeout_changed); + } else if (name == "notification_cloud_delay_ms") { + return send_closure(notification_manager_actor_, &NotificationManager::on_notification_cloud_delay_changed); + } else if (name == "notification_default_delay_ms") { + return send_closure(notification_manager_actor_, &NotificationManager::on_notification_default_delay_changed); } else if (is_internal_config_option(name)) { return; }