diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index 0d77a3d8b..67cac861c 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -534,7 +534,7 @@ void NotificationManager::try_reuse_notification_group_id(NotificationGroupId gr flush_pending_notifications_timeout_.cancel_timeout(group_id.get()); flush_pending_updates_timeout_.cancel_timeout(group_id.get()); if (pending_updates_.erase(group_id.get()) == 1) { - on_pending_notification_update_count_changed(-1); + on_pending_notification_update_count_changed(-1, group_id.get(), "try_reuse_notification_group_id"); } } @@ -636,7 +636,7 @@ void NotificationManager::add_notification(NotificationGroupId group_id, Notific flush_pending_notifications_timeout_.set_timeout_at(group_id.get(), group.pending_notifications_flush_time); } if (group.pending_notifications.empty()) { - on_pending_notification_update_count_changed(1); + on_pending_notification_update_count_changed(1, group_id.get(), "add_notification"); } group.pending_notifications.push_back(std::move(notification)); } @@ -686,7 +686,7 @@ void NotificationManager::add_update(int32 group_id, td_api::object_ptrtd(), &Td::send_update, std::move(update)); } - on_pending_notification_update_count_changed(-1); + on_pending_notification_update_count_changed(-1, group_id, "flush_pending_updates"); } void NotificationManager::flush_all_pending_updates(bool include_delayed_chats, const char *source) { @@ -1238,7 +1238,7 @@ void NotificationManager::flush_pending_notifications(NotificationGroupId group_ group.pending_notifications_flush_time = 0; group.pending_notifications.clear(); - on_pending_notification_update_count_changed(-1); + on_pending_notification_update_count_changed(-1, group_id.get(), "flush_pending_notifications"); // if we can delete a lot of notifications simultaneously if (group.notifications.size() > keep_notification_group_size_ + EXTRA_GROUP_SIZE && group.type != NotificationGroupType::Calls) { @@ -1447,7 +1447,7 @@ void NotificationManager::remove_notification(NotificationGroupId group_id, Noti if (group_it->second.pending_notifications.empty()) { group_it->second.pending_notifications_flush_time = 0; flush_pending_notifications_timeout_.cancel_timeout(group_id.get()); - on_pending_notification_update_count_changed(-1); + on_pending_notification_update_count_changed(-1, group_id.get(), "remove_notification"); } return promise.set_value(Unit()); } @@ -1550,7 +1550,7 @@ void NotificationManager::remove_notification_group(NotificationGroupId group_id if (group_it->second.pending_notifications.empty()) { group_it->second.pending_notifications_flush_time = 0; flush_pending_notifications_timeout_.cancel_timeout(group_id.get()); - on_pending_notification_update_count_changed(-1); + on_pending_notification_update_count_changed(-1, group_id.get(), "remove_notification_group"); } } if (new_total_count != -1) { @@ -1964,7 +1964,7 @@ void NotificationManager::before_get_difference() { } running_get_difference_ = true; - on_pending_notification_update_count_changed(1); + on_pending_notification_update_count_changed(1, 0, "before_get_difference"); } void NotificationManager::after_get_difference() { @@ -1974,7 +1974,7 @@ void NotificationManager::after_get_difference() { CHECK(running_get_difference_); running_get_difference_ = false; - on_pending_notification_update_count_changed(-1); + on_pending_notification_update_count_changed(-1, 0, "after_get_difference"); flush_pending_notifications_timeout_.set_timeout_in(0, MIN_NOTIFICATION_DELAY_MS * 1e-3); } @@ -1995,7 +1995,7 @@ void NotificationManager::before_get_chat_difference(NotificationGroupId group_i VLOG(notifications) << "Before get chat difference in " << group_id; CHECK(group_id.is_valid()); running_get_chat_difference_.insert(group_id.get()); - on_pending_notification_update_count_changed(1); + on_pending_notification_update_count_changed(1, group_id.get(), "before_get_chat_difference"); } void NotificationManager::after_get_chat_difference(NotificationGroupId group_id) { @@ -2008,7 +2008,7 @@ void NotificationManager::after_get_chat_difference(NotificationGroupId group_id auto erased_count = running_get_chat_difference_.erase(group_id.get()); if (erased_count == 1) { flush_pending_notifications_timeout_.set_timeout_in(-group_id.get(), MIN_NOTIFICATION_DELAY_MS * 1e-3); - on_pending_notification_update_count_changed(-1); + on_pending_notification_update_count_changed(-1, group_id.get(), "after_get_chat_difference"); } } @@ -2061,17 +2061,19 @@ void NotificationManager::destroy_all_notifications() { flush_all_pending_updates(true, "destroy_all_notifications"); if (pending_notification_update_count_ != 0) { - on_pending_notification_update_count_changed(-pending_notification_update_count_); + on_pending_notification_update_count_changed(-pending_notification_update_count_, 0, "destroy_all_notifications"); } is_destroyed_ = true; } -void NotificationManager::on_pending_notification_update_count_changed(int32 diff) { +void NotificationManager::on_pending_notification_update_count_changed(int32 diff, int32 notification_group_id, + const char *source) { bool had_pending = pending_notification_update_count_ != 0; pending_notification_update_count_ += diff; CHECK(pending_notification_update_count_ >= 0); VLOG(notifications) << "Update pending notification count with diff " << diff << " to " - << pending_notification_update_count_; + << pending_notification_update_count_ << " from group " << notification_group_id << " and " + << source; bool have_pending = pending_notification_update_count_ != 0; if (had_pending != have_pending && !is_destroyed_) { auto update = td_api::make_object(have_pending); diff --git a/td/telegram/NotificationManager.h b/td/telegram/NotificationManager.h index 848e80c99..0fd84e4f4 100644 --- a/td/telegram/NotificationManager.h +++ b/td/telegram/NotificationManager.h @@ -220,7 +220,7 @@ class NotificationManager : public Actor { void after_get_chat_difference_impl(NotificationGroupId group_id); - void on_pending_notification_update_count_changed(int32 diff); + void on_pending_notification_update_count_changed(int32 diff, int32 notification_group_id, const char *source); NotificationId current_notification_id_; NotificationGroupId current_notification_group_id_;