diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 79cc846b1..2f5aa7cd3 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -21820,7 +21820,8 @@ void MessagesManager::force_create_dialog(DialogId dialog_id, const char *source update_dialog_notification_settings(dialog_id, &d->notification_settings, user_d->notification_settings); } - if (G()->parameters().use_message_db && !td_->contacts_manager_->get_secret_chat_is_outbound(secret_chat_id)) { + if (G()->parameters().use_message_db && !td_->auth_manager_->is_bot() && + !td_->contacts_manager_->get_secret_chat_is_outbound(secret_chat_id)) { d->new_secret_chat_notification_id = get_next_notification_id(d, MessageId()); auto date = td_->contacts_manager_->get_secret_chat_date(secret_chat_id); bool is_changed = diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index b97d86ef1..0ca6a0396 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -112,25 +112,27 @@ void NotificationManager::start_up() { current_notification_group_id_ = NotificationGroupId(to_integer(G()->td_db()->get_binlog_pmc()->get("notification_group_id_current"))); - on_notification_group_count_max_changed(); + on_notification_group_count_max_changed(false); on_notification_group_size_max_changed(); on_online_cloud_timeout_changed(); on_notification_cloud_delay_changed(); on_notification_default_delay_changed(); - last_loaded_notification_group_key_.last_notification_date = std::numeric_limits::max(); + if (max_notification_group_count_ != 0) { + last_loaded_notification_group_key_.last_notification_date = std::numeric_limits::max(); - int32 loaded_groups = 0; - int32 needed_groups = static_cast(max_notification_group_count_); - do { - loaded_groups += load_message_notification_groups_from_database(needed_groups, false); - } while (loaded_groups < needed_groups && last_loaded_notification_group_key_.last_notification_date != 0); + int32 loaded_groups = 0; + int32 needed_groups = static_cast(max_notification_group_count_); + do { + loaded_groups += load_message_notification_groups_from_database(needed_groups, false); + } while (loaded_groups < needed_groups && last_loaded_notification_group_key_.last_notification_date != 0); - auto update = get_update_active_notificaitons(); - if (update != nullptr) { - VLOG(notifications) << "Send " << as_active_notifications_update(update.get()); - send_closure(G()->td(), &Td::send_update, std::move(update)); + auto update = get_update_active_notificaitons(); + if (update != nullptr) { + VLOG(notifications) << "Send " << as_active_notifications_update(update.get()); + send_closure(G()->td(), &Td::send_update, std::move(update)); + } } } @@ -182,6 +184,10 @@ NotificationManager::NotificationGroups::iterator NotificationManager::get_group } void NotificationManager::load_group_force(NotificationGroupId group_id) { + if (is_disabled() || max_notification_group_count_ == 0) { + return; + } + auto group_it = get_group_force(group_id, true); CHECK(group_it != groups_.end()); } @@ -558,7 +564,7 @@ int32 NotificationManager::get_notification_delay_ms(DialogId dialog_id, void NotificationManager::add_notification(NotificationGroupId group_id, DialogId dialog_id, int32 date, DialogId notification_settings_dialog_id, bool is_silent, NotificationId notification_id, unique_ptr type) { - if (is_disabled()) { + if (is_disabled() || max_notification_group_count_ == 0) { return; } @@ -1193,7 +1199,7 @@ void NotificationManager::flush_all_pending_notifications() { void NotificationManager::edit_notification(NotificationGroupId group_id, NotificationId notification_id, unique_ptr type) { - if (is_disabled()) { + if (is_disabled() || max_notification_group_count_ == 0) { return; } @@ -1346,7 +1352,7 @@ void NotificationManager::remove_notification(NotificationGroupId group_id, Noti return promise.set_error(Status::Error(400, "Notification identifier is invalid")); } - if (is_disabled()) { + if (is_disabled() || max_notification_group_count_ == 0) { return promise.set_value(Unit()); } @@ -1429,7 +1435,7 @@ void NotificationManager::remove_notification_group(NotificationGroupId group_id return promise.set_error(Status::Error(400, "Notification identifier is invalid")); } - if (is_disabled()) { + if (is_disabled() || max_notification_group_count_ == 0) { return promise.set_value(Unit()); } @@ -1525,7 +1531,7 @@ void NotificationManager::remove_notification_group(NotificationGroupId group_id promise.set_value(Unit()); } -void NotificationManager::on_notification_group_count_max_changed() { +void NotificationManager::on_notification_group_count_max_changed(bool send_updates) { if (is_disabled()) { return; } @@ -1544,7 +1550,7 @@ void NotificationManager::on_notification_group_count_max_changed() { << new_max_notification_group_count; bool is_increased = new_max_notification_group_count_size_t > max_notification_group_count_; - if (max_notification_group_count_ != 0) { + if (send_updates) { flush_all_pending_notifications(); flush_all_pending_updates(true, "on_notification_group_size_max_changed begin"); @@ -1569,6 +1575,14 @@ void NotificationManager::on_notification_group_count_max_changed() { } flush_all_pending_updates(true, "on_notification_group_size_max_changed end"); + + if (new_max_notification_group_count == 0) { + last_loaded_notification_group_key_ = NotificationGroupKey(); + last_loaded_notification_group_key_.last_notification_date = std::numeric_limits::max(); + CHECK(pending_updates_.empty()); + groups_.clear(); + group_keys_.clear(); + } } max_notification_group_count_ = new_max_notification_group_count_size_t; @@ -1674,10 +1688,18 @@ void NotificationManager::on_notification_default_delay_changed() { } void NotificationManager::before_get_difference() { + if (is_disabled()) { + return; + } + running_get_difference_ = true; } void NotificationManager::after_get_difference() { + if (is_disabled()) { + return; + } + CHECK(running_get_difference_); running_get_difference_ = false; flush_pending_notifications_timeout_.set_timeout_in(0, MIN_NOTIFICATION_DELAY_MS * 1e-3); @@ -1693,12 +1715,20 @@ void NotificationManager::after_get_difference_impl() { } void NotificationManager::before_get_chat_difference(NotificationGroupId group_id) { + if (is_disabled()) { + return; + } + VLOG(notifications) << "Before get chat difference in " << group_id; CHECK(group_id.is_valid()); running_get_chat_difference_.insert(group_id.get()); } void NotificationManager::after_get_chat_difference(NotificationGroupId group_id) { + if (is_disabled()) { + return; + } + VLOG(notifications) << "After get chat difference in " << group_id; CHECK(group_id.is_valid()); auto erased_count = running_get_chat_difference_.erase(group_id.get()); @@ -1721,7 +1751,7 @@ void NotificationManager::after_get_chat_difference_impl(NotificationGroupId gro } void NotificationManager::get_current_state(vector> &updates) const { - if (is_disabled()) { + if (is_disabled() || max_notification_group_count_ == 0) { return; } diff --git a/td/telegram/NotificationManager.h b/td/telegram/NotificationManager.h index b902f0e5a..890ddd665 100644 --- a/td/telegram/NotificationManager.h +++ b/td/telegram/NotificationManager.h @@ -37,7 +37,7 @@ class Td; class NotificationManager : public Actor { public: - static constexpr int32 MIN_NOTIFICATION_GROUP_COUNT_MAX = 1; + static constexpr int32 MIN_NOTIFICATION_GROUP_COUNT_MAX = 0; static constexpr int32 MAX_NOTIFICATION_GROUP_COUNT_MAX = 25; static constexpr int32 MIN_NOTIFICATION_GROUP_SIZE_MAX = 1; static constexpr int32 MAX_NOTIFICATION_GROUP_SIZE_MAX = 25; @@ -69,7 +69,7 @@ class NotificationManager : public Actor { void remove_notification_group(NotificationGroupId group_id, NotificationId max_notification_id, MessageId max_message_id, int32 new_total_count, Promise &&promise); - void on_notification_group_count_max_changed(); + void on_notification_group_count_max_changed(bool send_updates); void on_notification_group_size_max_changed(); @@ -90,7 +90,7 @@ class NotificationManager : public Actor { void get_current_state(vector> &updates) const; private: - static constexpr int32 DEFAULT_GROUP_COUNT_MAX = 10; + static constexpr int32 DEFAULT_GROUP_COUNT_MAX = 0; static constexpr int32 DEFAULT_GROUP_SIZE_MAX = 10; static constexpr size_t EXTRA_GROUP_SIZE = 10; @@ -192,6 +192,10 @@ class NotificationManager : public Actor { void flush_all_pending_updates(bool include_delayed_chats, const char *source); + void after_get_difference_impl(); + + void after_get_chat_difference_impl(NotificationGroupId group_id); + NotificationId current_notification_id_; NotificationGroupId current_notification_group_id_; @@ -213,10 +217,6 @@ class NotificationManager : public Actor { std::unordered_map>> pending_updates_; - void after_get_difference_impl(); - - void after_get_chat_difference_impl(NotificationGroupId group_id); - MultiTimeout flush_pending_notifications_timeout_{"FlushPendingNotificationsTimeout"}; MultiTimeout flush_pending_updates_timeout_{"FlushPendingUpdatesTimeout"}; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 8aef48854..90de8cb9e 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3570,7 +3570,7 @@ void Td::on_config_option_updated(const string &name) { send_closure(language_pack_manager_, &LanguagePackManager::on_language_pack_version_changed, -1); return; } else if (name == "notification_group_count_max") { - send_closure(notification_manager_actor_, &NotificationManager::on_notification_group_count_max_changed); + send_closure(notification_manager_actor_, &NotificationManager::on_notification_group_count_max_changed, true); } 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") {