From fe8cf6cd3d0747a968c79ee3227ad33f5d68ead0 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 24 Dec 2018 19:45:19 +0300 Subject: [PATCH] Add updateHavePendingNotifications. GitOrigin-RevId: 762b32f5a5d271f82c3f1c03efff92d8ccb7321d --- td/generate/scheme/td_api.tl | 3 +++ td/generate/scheme/td_api.tlo | Bin 139352 -> 139476 bytes td/telegram/NotificationManager.cpp | 39 +++++++++++++++++++++++++--- td/telegram/NotificationManager.h | 4 +++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index ba1008a9..fdae1518 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2271,6 +2271,9 @@ updateNotificationGroup notification_group_id:int32 type:NotificationGroupType c //@description Contains active notifications that was shown on previous application launches. This update is sent only if a message database is used. In that case it comes once before any updateNotification and updateNotificationGroup update @groups Lists of active notification groups updateActiveNotifications groups:vector = Update; +//@description Describes, whether there are some pending notification updates. Can be used to prevent application from killing, while there are some pending notifiations @have_pending_notifications True, if there are some pending notification updates, which will be sent soon +updateHavePendingNotifications have_pending_notifications:Bool = Update; + //@description Some messages were deleted @chat_id Chat identifier @message_ids Identifiers of the deleted messages //@is_permanent True, if the messages are permanently deleted by a user (as opposed to just becoming unaccessible) //@from_cache True, if the messages are deleted only from the cache and can possibly be retrieved again in the future diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 23c0fa86605e1f43f6b955e1cb89e669745f3aad..3f98fc39dc7c06bcf2318831f00c57c42c032f7e 100644 GIT binary patch delta 1734 zcmZWpUr1A76!-X#n;5Jx8fl?5V%4>zf)=b;_;2bquWd`G)7|N&n_Z{XiYS9Yf8GM~ z$_~YX1w9n_Ffg!(9wtfk;KLpaDvAs$d@%5#q6eY2efQj5={_BP-#NeY` zUf@!Jx~*Rh?|)G4o(TA(!J;#B7wT@7KSm z7Msnu8i7hod*})+c|ajw^Uz#tducM(UK(Uf#h$3xii&Z4 zlxOKHG~;omj|R1t*X&4N%^&4laCr)Rijy-A|x&nVS`9|6C&;9 zjR+amIN_%^nD�szHt3V!V4Wt2a6b7Da0Iltrt9^sEd+#4HSf#7@&Hwl+i$*c70= zK!E-N&jOlmCAj+~_|O_8=37CkNCnC6R~6F@lefuXH7^VTE{%W{EhBV6LL-_UW%7kr zM{*enCR7S3rSkeUJ*GnNhT)T8YM2VE*eK;@j_NTz3R5iCbzT{YY{4u(3?|w9AzgW~ zv7F~l-C4-(6O$52T#^*#_!!ZNH}rDym`>K;uE7aHF)^l0X?|@C-aXaRbIiSBE%*G# IoyC*fKbAdTEdT%j delta 1587 zcmY*ZUr1AN6!xrX3yf9>jT$s*4}-2WO2~&9EB|cjHm|wmoKCN9>eNkU_z>IxewE0YIp&Tzh)Ujf5vK1wZt-65I%B*cjs2y^;UXVqniL>pr5nQ*ynBW7Z zSQL5Pn^LSsP6e(qv!65)s~`Gpua%ul`N_w-HvA<_HSDFIuJeQ|0M*5g`2cx&Vm|<_ z>Ux*17_?<4+e=5tVV8qt{otq)sgAdcA|-gVCL&v$VD2D^C#E{UlHa?_E;*7yAENQNb8ad_-V~X-r1eOcabDj{okti-g`bt)o)3L2?O@J&lxtKFT zRT^D{tUO9Y;58e8*o_Fxo#>do2Uu?p>gIH84VW@VVCG&JaO+XJ7Yo?`kG)ck#T^Cl z<0#tl-xU}63uKmUnR2!lrE6U5NfffJeUL5op=+j(R(M@)KMDF_61#WSaDzDmc+a_h zu;lx}a;QfR2}hBUz`QI$yk(%|>lxVxiF)M1eIt82KuJE^GN>KJQl&w=uK7U_7A4v$AMRH6N*VPmM@ zzQyZ(<21u_+vA#p&q=aqr(jLNf;R=W3@}-GYGL^l1$n<^Lfge^VuE(xS@6SLru;o> Ss1Qu`&(>9JHEc0tO#c8 update) { VLOG(notifications) << "Add " << as_notification_update(update.get()); - pending_updates_[group_id].push_back(std::move(update)); + auto &updates = pending_updates_[group_id]; + if (updates.empty()) { + on_pending_notification_update_count_changed(1); + } + updates.push_back(std::move(update)); if (!running_get_difference_ && running_get_chat_difference_.count(group_id) == 0) { flush_pending_updates_timeout_.add_timeout_in(group_id, MIN_UPDATE_DELAY_MS * 1e-3); } else { @@ -1023,13 +1032,14 @@ void NotificationManager::flush_pending_updates(int32 group_id, const char *sour VLOG(notifications) << "Send " << as_notification_update(update.get()); send_closure(G()->td(), &Td::send_update, std::move(update)); } + on_pending_notification_update_count_changed(-1); } void NotificationManager::flush_all_pending_updates(bool include_delayed_chats, const char *source) { VLOG(notifications) << "Flush all pending notification updates " << (include_delayed_chats ? "with delayed chats " : "") << "from " << source; vector ready_group_keys; - for (auto &it : pending_updates_) { + for (const auto &it : pending_updates_) { if (include_delayed_chats || running_get_chat_difference_.count(it.first) == 0) { auto group_it = get_group(NotificationGroupId(it.first)); CHECK(group_it != groups_.end()); @@ -1218,6 +1228,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); // if we can delete a lot of notifications simultaneously if (group.notifications.size() > keep_notification_group_size_ + EXTRA_GROUP_SIZE && group.type != NotificationGroupType::Calls) { @@ -1423,6 +1434,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); } return promise.set_value(Unit()); } @@ -1524,6 +1536,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); } if (new_total_count != -1) { new_total_count -= static_cast(group_it->second.pending_notifications.size()); @@ -1893,6 +1906,7 @@ void NotificationManager::before_get_difference() { } running_get_difference_ = true; + on_pending_notification_update_count_changed(1); } void NotificationManager::after_get_difference() { @@ -1902,6 +1916,7 @@ void NotificationManager::after_get_difference() { CHECK(running_get_difference_); running_get_difference_ = false; + on_pending_notification_update_count_changed(-1); flush_pending_notifications_timeout_.set_timeout_in(0, MIN_NOTIFICATION_DELAY_MS * 1e-3); } @@ -1922,6 +1937,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); } void NotificationManager::after_get_chat_difference(NotificationGroupId group_id) { @@ -1934,6 +1950,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); } } @@ -1964,6 +1981,7 @@ void NotificationManager::get_current_state(vector= 0); + bool have_pending = pending_notification_update_count_ != 0; + if (had_pending != have_pending && !is_destroyed_) { + auto update = td_api::make_object(have_pending); + VLOG(notifications) << "Send " << oneline(to_string(update)); + send_closure(G()->td(), &Td::send_update, std::move(update)); + } +} + } // namespace td diff --git a/td/telegram/NotificationManager.h b/td/telegram/NotificationManager.h index 932013ae..65371bf0 100644 --- a/td/telegram/NotificationManager.h +++ b/td/telegram/NotificationManager.h @@ -218,6 +218,8 @@ class NotificationManager : public Actor { void after_get_chat_difference_impl(NotificationGroupId group_id); + void on_pending_notification_update_count_changed(int32 diff); + NotificationId current_notification_id_; NotificationGroupId current_notification_group_id_; @@ -229,6 +231,8 @@ class NotificationManager : public Actor { int32 notification_cloud_delay_ms_ = DEFAULT_ONLINE_CLOUD_DELAY_MS; int32 notification_default_delay_ms_ = DEFAULT_DEFAULT_DELAY_MS; + int32 pending_notification_update_count_ = 0; + NotificationGroupKey last_loaded_notification_group_key_; bool is_destroyed_ = false;