From d772ab6de0d1ff890066ca2d93182493cae0eea0 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 5 Dec 2018 19:11:28 +0300 Subject: [PATCH] Support updateActiveNotifications in getCurrentState. GitOrigin-RevId: a0fddcbbd4c54bf338b3e84d0355849e848c7524 --- td/telegram/NotificationManager.cpp | 28 ++++++++++++++++++++++++---- td/telegram/NotificationManager.h | 4 ++++ td/telegram/Td.cpp | 2 ++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index a4da34c71..b7545d95b 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -125,6 +125,15 @@ void NotificationManager::start_up() { 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)); + } +} + +td_api::object_ptr NotificationManager::get_update_active_notificaitons() const { + auto needed_groups = max_notification_group_count_; vector> groups; for (auto &group : groups_) { if (needed_groups == 0 || group.first.last_notification_date == 0) { @@ -144,11 +153,11 @@ void NotificationManager::start_up() { group.first.group_id.get(), group.first.dialog_id.get(), group.second.total_count, std::move(notifications))); } } - if (!groups.empty()) { - auto update = td_api::make_object(std::move(groups)); - VLOG(notifications) << "Send " << as_active_notifications_update(update.get()); - send_closure(G()->td(), &Td::send_update, std::move(update)); + if (groups.empty()) { + return nullptr; } + + return td_api::make_object(std::move(groups)); } void NotificationManager::tear_down() { @@ -1694,4 +1703,15 @@ void NotificationManager::after_get_chat_difference_impl(NotificationGroupId gro } } +void NotificationManager::get_current_state(vector> &updates) const { + if (is_disabled()) { + return; + } + + auto update = get_update_active_notificaitons(); + if (update != nullptr) { + updates.push_back(std::move(update)); + } +} + } // namespace td diff --git a/td/telegram/NotificationManager.h b/td/telegram/NotificationManager.h index 95f8529cc..c20bef38c 100644 --- a/td/telegram/NotificationManager.h +++ b/td/telegram/NotificationManager.h @@ -84,6 +84,8 @@ class NotificationManager : public Actor { void after_get_chat_difference(NotificationGroupId group_id); + void get_current_state(vector> &updates) const; + private: static constexpr int32 DEFAULT_GROUP_COUNT_MAX = 10; static constexpr int32 DEFAULT_GROUP_SIZE_MAX = 10; @@ -157,6 +159,8 @@ class NotificationManager : public Actor { NotificationGroupKey get_last_updated_group_key() const; + td_api::object_ptr get_update_active_notificaitons() const; + void send_remove_group_update(const NotificationGroupKey &group_key, const NotificationGroup &group, vector &&removed_notification_ids); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 948e71c13..2e4d036d2 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -4532,6 +4532,8 @@ void Td::on_request(uint64 id, const td_api::getCurrentState &request) { messages_manager_->get_current_state(updates); + notification_manager_->get_current_state(updates); + // TODO updateFileGenerationStart generation_id:int64 original_path:string destination_path:string conversion:string = Update; // TODO updateCall call:call = Update; }