From a05c43ceeb8f6d5989b723fdaac9759a26ef5cbd Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 24 Dec 2018 00:34:40 +0300 Subject: [PATCH] Add NotificationGroupType. GitOrigin-RevId: 328adc5df3cbe278008c11d5a35da93da88b7d41 --- CMakeLists.txt | 1 + td/generate/scheme/td_api.tl | 27 +++++++-- td/generate/scheme/td_api.tlo | Bin 138792 -> 139192 bytes td/telegram/MessagesManager.cpp | 9 ++- td/telegram/MessagesManager.h | 2 + td/telegram/NotificationGroupType.h | 67 ++++++++++++++++++++++ td/telegram/NotificationManager.cpp | 84 ++++++++++++++++------------ td/telegram/NotificationManager.h | 5 +- td/telegram/NotificationType.cpp | 12 ---- td/telegram/NotificationType.h | 2 - 10 files changed, 148 insertions(+), 61 deletions(-) create mode 100644 td/telegram/NotificationGroupType.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c946a28..68260236 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -540,6 +540,7 @@ set(TDLIB_SOURCE td/telegram/Notification.h td/telegram/NotificationGroupId.h td/telegram/NotificationGroupKey.h + td/telegram/NotificationGroupType.h td/telegram/NotificationId.h td/telegram/NotificationManager.h td/telegram/NotificationSettings.h diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 24edc1e2..5e227ffb 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1355,7 +1355,7 @@ searchMessagesFilterVoiceAndVideoNote = SearchMessagesFilter; //@description Returns only messages with mentions of the current user, or messages that are replies to their messages searchMessagesFilterMention = SearchMessagesFilter; -//@description Returns only messages with unread mentions of the current user or messages that are replies to their messages. When using this filter the results can't be additionally filtered by a query or by the sending user +//@description Returns only messages with unread mentions of the current user, or messages that are replies to their messages. When using this filter the results can't be additionally filtered by a query or by the sending user searchMessagesFilterUnreadMention = SearchMessagesFilter; @@ -1815,12 +1815,28 @@ notificationTypeNewSecretChat = NotificationType; notificationTypeNewCall call_id:int32 = NotificationType; +//@class NotificationGroupType @description Describes type of notifications in the group + +//@description A group containing notifications of type notificationTypeNewMessage with ordinary unread messages +notificationGroupTypeMessages = NotificationGroupType; + +//@description A group containing notifications of type notificationTypeNewMessage with unread mentions of the current user, replies to their messages, or a pinned message +notificationGroupTypeMentions = NotificationGroupType; + +//@description A group containing a notification of type notificationTypeSecretChat +notificationGroupTypeSecretChat = NotificationGroupType; + +//@description A group containing notifications of type notificationTypeNewCall +notificationGroupTypeCalls = NotificationGroupType; + + //@description Contains information about a notification @id Unique persistent identifier of this notification @date Notification date @type Notification type notification id:int32 date:int32 type:NotificationType = Notification; -//@description Describes a group of notifications @id Unique persistent auto-incremented from 1 identifier of the notification group @chat_id Identifier of a chat to which all notifications in the group belong +//@description Describes a group of notifications @id Unique persistent auto-incremented from 1 identifier of the notification group @type Type of the group +//@chat_id Identifier of a chat to which all notifications in the group belong //@total_count Total number of active notifications in the group @notifications The list of active notifications -notificationGroup id:int32 chat_id:int53 total_count:int32 notifications:vector = NotificationGroup; +notificationGroup id:int32 type:NotificationGroupType chat_id:int53 total_count:int32 notifications:vector = NotificationGroup; //@class OptionValue @description Represents the value of an option @@ -2246,10 +2262,11 @@ updateChatDraftMessage chat_id:int53 draft_message:draftMessage order:int64 = Up //@description A notification was changed @notification_group_id Unique notification group identifier @notification Changed notification updateNotification notification_group_id:int32 notification:notification = Update; -//@description A list of active notifications in a notification group has changed @notification_group_id Unique notification group identifier @chat_id Identifier of a chat to which all notifications in the group belong +//@description A list of active notifications in a notification group has changed @notification_group_id Unique notification group identifier @type New type of the notification group +//@chat_id Identifier of a chat to which all notifications in the group belong //@notification_settings_chat_id Chat identifier, which notification settings must be applied @is_silent True, if the notifications should be shown without sound //@total_count Total number of active notifications in the group @added_notifications List of added group notifications @removed_notification_ids Identifiers of removed group notifications -updateNotificationGroup notification_group_id:int32 chat_id:int53 notification_settings_chat_id:int53 is_silent:Bool total_count:int32 added_notifications:vector removed_notification_ids:vector = Update; +updateNotificationGroup notification_group_id:int32 type:NotificationGroupType chat_id:int53 notification_settings_chat_id:int53 is_silent:Bool total_count:int32 added_notifications:vector removed_notification_ids:vector = Update; //@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; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index cf9ab7ab1431ef64811e538ecf37603574c243ce..632d9d5ccdbdedd08d74b75288b014271870efca 100644 GIT binary patch delta 2103 zcma)7Ur1YL6u-wt$x7VPHqx-gHLZC_>9q~ig3JmsV-s!uX-th8HPKv6+Ni;#;FypM zZ0A6j>)rYdD=ZI#bwv6y>sq0PWrxEul@R%$`@HUE9Q^!_1|7tK2hhIPDaP0W1(bp zddfC4eLdd$MqJ=HmG~DN-_YuewY3)~Q@_>t;^9zI;M&S?@5$I9NNwzx-rhD)wj)yq zNjQ$;BsT&2TT@5G#+H|=X*N!LEB|hax=_+LuO1H6pTD_W{|p7y;S>^y(1eiSI2!%K ziYLa;z(gE22_myLDJjX=Aj1Nz zb_uHlY#~JQc1&N96zi0*O28kT(8SnGU0`IEy$h?Eld((}c$jxzi8YFoEw9|_R5MrX zvZ4ZUvBgT#4v>602hx|Q8p)rRp@9W0I+Ru99AIZS@5BO10X$i7qNpvWA`8*Ez`+8- zE@);}#sv{(Y1~Tkpc{e=f9S@>7TgeKnBRjL$_Xo-DLn1)bYsgFx-nv_8<~wg$V^$p zl~$f;FJKea&`Ad%?zWnV#fx+G%U0S85golH%H{m%lb>&pq8Ie?{ZW%&x}lCNd*PJG zw`irsKKb~}X0jJFz>1ppVHfZDz@n!s4-ze|Z~1x`eX?vD@V7J2Oct-;$a7aJ9e0w+ zeH>l755>3LDUHZ*7PLe^2^v!9!-|W2U|>oNer%SUD^6+2!&XNkuf-of_H~; zJbw>EmgUw_D#k|KIj*nzz_;t(`-@2GFd`0{A$#+yD}{ zjE&I6tym-2cB*ndFYNN@+1q$IN{!&a>4se8pN-JU!`w|^ylfbi95zysEJ%1iAgRSGoIAS zNUeosSeMI&e!=s;6`Y*HC_|K6x8*HWvN9;#;b;>~Z4l@V^En%A#ktOLwq zuXbQtJM6)d4mik^170+a$5W$L6E)^&p2tey#IWY=o9ONN@euT*|ab&{Ukib*)~ z7@SzqMK7M{B5zKu7yqu)+Znqx(M+j#;p9~)#bh_FLaG}oxQeN6n%OcXpy49T!hMlC zj|yx;V2gx3=-I3#p|6J;8y1%PVeYb4dx+QKrx4jsYcMCUAAai29Uz@bfOL)pKoaxS zH2V7rWO-$Oh)yXPqTKhP0>L`;9?c1M^nqK`+DFWjeRLZueZ*|+hZv7b z_7gVMPiMFxFl(5Oc_>^^tq7N1Ll6xSVy=r2OCm!3J`q?pLcO^ziMTy)BeCY!!##zYhrIqn*ydWk`SU8dML7GZlv$&&=w(t3QAB>I%tc JT;;mkhJVJ3aKZop diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index aed84d6c..e8d46569 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -28,6 +28,7 @@ #include "td/telegram/net/DcId.h" #include "td/telegram/net/NetActor.h" #include "td/telegram/net/NetQuery.h" +#include "td/telegram/NotificationGroupType.h" #include "td/telegram/NotificationManager.h" #include "td/telegram/NotificationSettings.hpp" #include "td/telegram/NotificationType.h" @@ -17639,6 +17640,7 @@ MessagesManager::MessageNotificationGroup MessagesManager::get_message_notificat MessageNotificationGroup result; VLOG(notifications) << "Found " << d->dialog_id << " by " << group_id; result.dialog_id = d->dialog_id; + result.type = from_mentions ? NotificationGroupType::Mentions : NotificationGroupType::Messages; result.total_count = get_dialog_pending_notification_count(d, from_mentions); result.total_count -= static_cast(from_mentions ? d->pending_new_mention_notifications.size() : d->pending_new_message_notifications.size()); @@ -18142,7 +18144,8 @@ bool MessagesManager::add_new_message_notification(Dialog *d, Message *m, bool f CHECK(is_changed); VLOG(notifications) << "Create " << m->notification_id << " with " << m->message_id << " in " << d->dialog_id; send_closure_later(G()->notification_manager(), &NotificationManager::add_notification, notification_group_id, - d->dialog_id, m->date, settings_dialog_id, m->disable_notification, m->notification_id, + from_mentions ? NotificationGroupType::Mentions : NotificationGroupType::Messages, d->dialog_id, + m->date, settings_dialog_id, m->disable_notification, m->notification_id, create_new_message_notification(m->message_id)); return true; } @@ -21858,8 +21861,8 @@ void MessagesManager::force_create_dialog(DialogId dialog_id, const char *source CHECK(is_changed); VLOG(notifications) << "Create " << d->new_secret_chat_notification_id << " with " << secret_chat_id; send_closure_later(G()->notification_manager(), &NotificationManager::add_notification, notification_group_id, - dialog_id, date, dialog_id, false, d->new_secret_chat_notification_id, - create_new_secret_chat_notification()); + NotificationGroupType::SecretChat, dialog_id, date, dialog_id, false, + d->new_secret_chat_notification_id, create_new_secret_chat_notification()); } } if (!have_input_peer(dialog_id, AccessRights::Read)) { diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 915671f0..e65370b0 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -26,6 +26,7 @@ #include "td/telegram/Notification.h" #include "td/telegram/NotificationGroupId.h" #include "td/telegram/NotificationGroupKey.h" +#include "td/telegram/NotificationGroupType.h" #include "td/telegram/NotificationId.h" #include "td/telegram/NotificationSettings.h" #include "td/telegram/ReplyMarkup.h" @@ -655,6 +656,7 @@ class MessagesManager : public Actor { struct MessageNotificationGroup { DialogId dialog_id; + NotificationGroupType type = NotificationGroupType::Calls; int32 total_count = 0; vector notifications; }; diff --git a/td/telegram/NotificationGroupType.h b/td/telegram/NotificationGroupType.h new file mode 100644 index 00000000..abb46002 --- /dev/null +++ b/td/telegram/NotificationGroupType.h @@ -0,0 +1,67 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#pragma once + +#include "td/telegram/td_api.h" + +#include "td/utils/logging.h" +#include "td/utils/StringBuilder.h" + +namespace td { + +enum class NotificationGroupType : int8 { Messages, Mentions, SecretChat, Calls }; + +inline td_api::object_ptr get_notification_group_type_object(NotificationGroupType type) { + switch (type) { + case NotificationGroupType::Messages: + return td_api::make_object(); + case NotificationGroupType::Mentions: + return td_api::make_object(); + case NotificationGroupType::SecretChat: + return td_api::make_object(); + case NotificationGroupType::Calls: + return td_api::make_object(); + default: + UNREACHABLE(); + return nullptr; + } +} + +inline NotificationGroupType get_notification_group_type(const td_api::object_ptr &type) { + CHECK(type != nullptr); + switch (type->get_id()) { + case td_api::notificationGroupTypeMessages::ID: + return NotificationGroupType::Messages; + case td_api::notificationGroupTypeMentions::ID: + return NotificationGroupType::Mentions; + case td_api::notificationGroupTypeSecretChat::ID: + return NotificationGroupType::SecretChat; + case td_api::notificationGroupTypeCalls::ID: + return NotificationGroupType::Calls; + default: + UNREACHABLE(); + return NotificationGroupType::Calls; + } +} + +inline StringBuilder &operator<<(StringBuilder &sb, const NotificationGroupType &type) { + switch (type) { + case NotificationGroupType::Messages: + return sb << "Messages"; + case NotificationGroupType::Mentions: + return sb << "Mentions"; + case NotificationGroupType::SecretChat: + return sb << "SecretChat"; + case NotificationGroupType::Calls: + return sb << "Calls"; + default: + UNREACHABLE(); + return sb; + } +} + +} // namespace td diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index 5c27aa3a..fad8dfee 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -91,7 +91,8 @@ StringBuilder &operator<<(StringBuilder &string_builder, const ActiveNotificatio added_notification_ids.push_back(notification->id_); } - string_builder << " [" << NotificationGroupId(group->id_) << " from " << DialogId(group->chat_id_) + string_builder << " [" << NotificationGroupId(group->id_) << " of type " + << get_notification_group_type(group->type_) << " from " << DialogId(group->chat_id_) << "; total_count = " << group->total_count_ << ", restore " << added_notification_ids << "]\n"; } return string_builder << ']'; @@ -165,7 +166,8 @@ td_api::object_ptr NotificationManager::get_u } if (!notifications.empty()) { groups.push_back(td_api::make_object( - group.first.group_id.get(), group.first.dialog_id.get(), group.second.total_count, std::move(notifications))); + group.first.group_id.get(), get_notification_group_type_object(group.second.type), + group.first.dialog_id.get(), group.second.total_count, std::move(notifications))); } } if (groups.empty()) { @@ -228,6 +230,7 @@ NotificationManager::NotificationGroups::iterator NotificationManager::get_group } NotificationGroup group; + group.type = message_group.type; group.total_count = message_group.total_count; group.notifications = std::move(message_group.notifications); @@ -303,7 +306,8 @@ void NotificationManager::load_message_notifications_from_database(const Notific if (!G()->parameters().use_message_db) { return; } - if (group.is_loaded_from_database || group.is_being_loaded_from_database || !group.contains_messages) { + if (group.is_loaded_from_database || group.is_being_loaded_from_database || + group.type == NotificationGroupType::Calls) { return; } if (group.total_count == 0) { @@ -455,8 +459,8 @@ void NotificationManager::add_notifications_to_group_begin(NotificationGroups::i if (!added_notifications.empty()) { add_update_notification_group(td_api::make_object( - group_key.group_id.get(), group_key.dialog_id.get(), 0, true, group.total_count, - std::move(added_notifications), vector())); + group_key.group_id.get(), get_notification_group_type_object(group.type), group_key.dialog_id.get(), 0, true, + group.total_count, std::move(added_notifications), vector())); } } @@ -577,9 +581,10 @@ int32 NotificationManager::get_notification_delay_ms(DialogId dialog_id, return max(delay_ms - passed_time_ms, MIN_NOTIFICATION_DELAY_MS); } -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) { +void NotificationManager::add_notification(NotificationGroupId group_id, NotificationGroupType group_type, + DialogId dialog_id, int32 date, DialogId notification_settings_dialog_id, + bool is_silent, NotificationId notification_id, + unique_ptr type) { if (is_disabled() || max_notification_group_count_ == 0) { return; } @@ -589,19 +594,18 @@ void NotificationManager::add_notification(NotificationGroupId group_id, DialogI CHECK(notification_settings_dialog_id.is_valid()); CHECK(notification_id.is_valid()); CHECK(type != nullptr); - VLOG(notifications) << "Add " << notification_id << " to " << group_id << " in " << dialog_id - << " with settings from " << notification_settings_dialog_id + VLOG(notifications) << "Add " << notification_id << " to " << group_id << " of type " << group_type << " in " + << dialog_id << " with settings from " << notification_settings_dialog_id << (is_silent ? " silently" : " with sound") << ": " << *type; auto group_it = get_group_force(group_id); if (group_it == groups_.end()) { group_it = add_group(NotificationGroupKey(group_id, dialog_id, 0), NotificationGroup()); - if (type->get_call_id().is_valid()) { - group_it->second.contains_messages = false; - } } - - CHECK(group_it->second.contains_messages == !type->get_call_id().is_valid()); + if (group_it->second.notifications.empty() && group_it->second.pending_notifications.empty()) { + group_it->second.type = group_type; + } + CHECK(group_it->second.type == group_type); PendingNotification notification; notification.date = date; @@ -645,9 +649,9 @@ StringBuilder &operator<<(StringBuilder &string_builder, const NotificationUpdat added_notification_ids.push_back(notification->id_); } - return string_builder << "update[" << NotificationGroupId(p->notification_group_id_) << " from " - << DialogId(p->chat_id_) << " with settings from " - << DialogId(p->notification_settings_chat_id_) + return string_builder << "update[" << NotificationGroupId(p->notification_group_id_) << " of type " + << get_notification_group_type(p->type_) << " from " << DialogId(p->chat_id_) + << " with settings from " << DialogId(p->notification_settings_chat_id_) << (p->is_silent_ ? " silently" : " with sound") << "; total_count = " << p->total_count_ << ", add " << added_notification_ids << ", remove " << p->removed_notification_ids_; } @@ -878,6 +882,7 @@ void NotificationManager::flush_pending_updates(int32 group_id, const char *sour if (updates[i - 1] != nullptr && updates[i - 1]->get_id() == td_api::updateNotificationGroup::ID) { VLOG(notifications) << "Move total_count from empty update " << cur_pos << " to update " << i; auto previous_update_ptr = static_cast(updates[i - 1].get()); + previous_update_ptr->type_ = std::move(update_ptr->type_); previous_update_ptr->total_count_ = update_ptr->total_count_; is_changed = true; update = nullptr; @@ -991,6 +996,7 @@ void NotificationManager::flush_pending_updates(int32 group_id, const char *sour if (last_update_ptr->is_silent_ && !update_ptr->is_silent_) { last_update_ptr->is_silent_ = false; } + last_update_ptr->type_ = std::move(update_ptr->type_); last_update_ptr->total_count_ = update_ptr->total_count_; append(last_update_ptr->added_notifications_, std::move(update_ptr->added_notifications_)); append(last_update_ptr->removed_notification_ids_, std::move(update_ptr->removed_notification_ids_)); @@ -1077,9 +1083,9 @@ void NotificationManager::do_flush_pending_notifications(NotificationGroupKey &g if (!added_notifications.empty()) { add_update_notification_group(td_api::make_object( - group_key.group_id.get(), group_key.dialog_id.get(), pending_notifications[0].settings_dialog_id.get(), - pending_notifications[0].is_silent, group.total_count, std::move(added_notifications), - std::move(removed_notification_ids))); + group_key.group_id.get(), get_notification_group_type_object(group.type), group_key.dialog_id.get(), + pending_notifications[0].settings_dialog_id.get(), pending_notifications[0].is_silent, group.total_count, + std::move(added_notifications), std::move(removed_notification_ids))); } else { CHECK(removed_notification_ids.empty()); } @@ -1100,8 +1106,9 @@ void NotificationManager::send_remove_group_update(const NotificationGroupKey &g if (!removed_notification_ids.empty()) { add_update_notification_group(td_api::make_object( - group_key.group_id.get(), group_key.dialog_id.get(), group_key.dialog_id.get(), true, group.total_count, - vector>(), std::move(removed_notification_ids))); + group_key.group_id.get(), get_notification_group_type_object(group.type), group_key.dialog_id.get(), + group_key.dialog_id.get(), true, group.total_count, vector>(), + std::move(removed_notification_ids))); } } @@ -1120,8 +1127,8 @@ void NotificationManager::send_add_group_update(const NotificationGroupKey &grou if (!added_notifications.empty()) { add_update_notification_group(td_api::make_object( - group_key.group_id.get(), group_key.dialog_id.get(), 0, true, group.total_count, std::move(added_notifications), - vector())); + group_key.group_id.get(), get_notification_group_type_object(group.type), group_key.dialog_id.get(), 0, true, + group.total_count, std::move(added_notifications), vector())); } } @@ -1193,7 +1200,8 @@ void NotificationManager::flush_pending_notifications(NotificationGroupId group_ group.pending_notifications_flush_time = 0; group.pending_notifications.clear(); // if we can delete a lot of notifications simultaneously - if (group.notifications.size() > keep_notification_group_size_ + EXTRA_GROUP_SIZE && group.contains_messages) { + if (group.notifications.size() > keep_notification_group_size_ + EXTRA_GROUP_SIZE && + group.type != NotificationGroupType::Calls) { // keep only keep_notification_group_size_ last notifications in memory group.notifications.erase(group.notifications.begin(), group.notifications.end() - keep_notification_group_size_); group.is_loaded_from_database = false; @@ -1291,8 +1299,8 @@ void NotificationManager::on_notifications_removed( if (is_updated) { // group is still visible add_update_notification_group(td_api::make_object( - group_key.group_id.get(), group_key.dialog_id.get(), 0, true, group.total_count, - std::move(added_notifications), std::move(removed_notification_ids))); + group_key.group_id.get(), get_notification_group_type_object(group.type), group_key.dialog_id.get(), 0, true, + group.total_count, std::move(added_notifications), std::move(removed_notification_ids))); } else { // group needs to be removed send_remove_group_update(group_key, group, std::move(removed_notification_ids)); @@ -1383,7 +1391,7 @@ void NotificationManager::remove_notification(NotificationGroupId group_id, Noti return promise.set_value(Unit()); } - if (!is_permanent && group_it->second.contains_messages) { + if (!is_permanent && group_it->second.type != NotificationGroupType::Calls) { td_->messages_manager_->remove_message_notification(group_it->first.dialog_id, group_id, notification_id); } @@ -1411,7 +1419,8 @@ void NotificationManager::remove_notification(NotificationGroupId group_id, Noti } bool is_total_count_changed = false; - if ((group_it->second.contains_messages && is_permanent) || (!group_it->second.contains_messages && is_found)) { + if ((group_it->second.type != NotificationGroupType::Calls && is_permanent) || + (group_it->second.type == NotificationGroupType::Calls && is_found)) { if (group_it->second.total_count == 0) { LOG(ERROR) << "Total notification count became negative in " << group_id << " after removing " << notification_id; } else { @@ -1478,7 +1487,7 @@ void NotificationManager::remove_notification_group(NotificationGroupId group_id if (max_notification_id.get() > current_notification_id_.get()) { max_notification_id = current_notification_id_; } - if (group_it->second.contains_messages) { + if (group_it->second.type != NotificationGroupType::Calls) { td_->messages_manager_->remove_message_notifications(group_it->first.dialog_id, group_id, max_notification_id); } } @@ -1529,7 +1538,7 @@ void NotificationManager::remove_notification_group(NotificationGroupId group_id group_it->second.notifications.erase(group_it->second.notifications.begin(), group_it->second.notifications.begin() + notification_delete_end); } - if (!group_it->second.contains_messages) { + if (group_it->second.type == NotificationGroupType::Calls) { new_total_count = static_cast(group_it->second.notifications.size()); } if (group_it->second.total_count == new_total_count) { @@ -1624,8 +1633,8 @@ void NotificationManager::add_call_notification(DialogId dialog_id, CallId call_ auto notification_id = get_next_notification_id(); active_notifications.push_back(ActiveCallNotification{call_id, notification_id}); - add_notification(group_id, dialog_id, G()->unix_time() + 120, dialog_id, false, notification_id, - create_new_call_notification(call_id)); + add_notification(group_id, NotificationGroupType::Calls, dialog_id, G()->unix_time() + 120, dialog_id, false, + notification_id, create_new_call_notification(call_id)); } void NotificationManager::remove_call_notification(DialogId dialog_id, CallId call_id) { @@ -1665,7 +1674,7 @@ void NotificationManager::remove_call_notification(DialogId dialog_id, CallId ca CHECK(group_it->second.total_count == 0); CHECK(group_it->second.notifications.empty()); CHECK(group_it->second.pending_notifications.empty()); - CHECK(!group_it->second.contains_messages); + CHECK(group_it->second.type == NotificationGroupType::Calls); CHECK(!group_it->second.is_being_loaded_from_database); CHECK(pending_updates_.count(group_id.get()) == 0); delete_group(std::move(group_it)); @@ -1803,8 +1812,9 @@ void NotificationManager::on_notification_group_size_max_changed() { } } auto update = td_api::make_object( - group_key.group_id.get(), group_key.dialog_id.get(), group_key.dialog_id.get(), true, group.total_count, - std::move(added_notifications), std::move(removed_notification_ids)); + group_key.group_id.get(), get_notification_group_type_object(group.type), group_key.dialog_id.get(), + group_key.dialog_id.get(), true, group.total_count, std::move(added_notifications), + std::move(removed_notification_ids)); VLOG(notifications) << "Send " << as_notification_update(update.get()); send_closure(G()->td(), &Td::send_update, std::move(update)); } diff --git a/td/telegram/NotificationManager.h b/td/telegram/NotificationManager.h index ee054021..28825266 100644 --- a/td/telegram/NotificationManager.h +++ b/td/telegram/NotificationManager.h @@ -12,6 +12,7 @@ #include "td/telegram/Notification.h" #include "td/telegram/NotificationGroupId.h" #include "td/telegram/NotificationGroupKey.h" +#include "td/telegram/NotificationGroupType.h" #include "td/telegram/NotificationId.h" #include "td/telegram/NotificationType.h" #include "td/telegram/td_api.h" @@ -57,7 +58,7 @@ class NotificationManager : public Actor { void load_group_force(NotificationGroupId group_id); - void add_notification(NotificationGroupId group_id, DialogId dialog_id, int32 date, + void add_notification(NotificationGroupId group_id, NotificationGroupType group_type, DialogId dialog_id, int32 date, DialogId notification_settings_dialog_id, bool is_silent, NotificationId notification_id, unique_ptr type); @@ -121,9 +122,9 @@ class NotificationManager : public Actor { struct NotificationGroup { int32 total_count = 0; + NotificationGroupType type = NotificationGroupType::Calls; bool is_loaded_from_database = false; bool is_being_loaded_from_database = false; - bool contains_messages = true; vector notifications; diff --git a/td/telegram/NotificationType.cpp b/td/telegram/NotificationType.cpp index abdd2b46..2ad1e751 100644 --- a/td/telegram/NotificationType.cpp +++ b/td/telegram/NotificationType.cpp @@ -20,10 +20,6 @@ class NotificationTypeMessage : public NotificationType { return message_id_; } - CallId get_call_id() const override { - return CallId(); - } - td_api::object_ptr get_notification_type_object(DialogId dialog_id) const override { auto message_object = G()->td().get_actor_unsafe()->messages_manager_->get_message_object({dialog_id, message_id_}); if (message_object == nullptr) { @@ -56,10 +52,6 @@ class NotificationTypeSecretChat : public NotificationType { return MessageId(); } - CallId get_call_id() const override { - return CallId(); - } - td_api::object_ptr get_notification_type_object(DialogId dialog_id) const override { return td_api::make_object(); } @@ -86,10 +78,6 @@ class NotificationTypeCall : public NotificationType { return MessageId::max(); } - CallId get_call_id() const override { - return call_id_; - } - td_api::object_ptr get_notification_type_object(DialogId dialog_id) const override { return td_api::make_object(call_id_.get()); } diff --git a/td/telegram/NotificationType.h b/td/telegram/NotificationType.h index 15b40b86..b547d367 100644 --- a/td/telegram/NotificationType.h +++ b/td/telegram/NotificationType.h @@ -31,8 +31,6 @@ class NotificationType { virtual MessageId get_message_id() const = 0; - virtual CallId get_call_id() const = 0; - virtual td_api::object_ptr get_notification_type_object(DialogId dialog_id) const = 0; virtual StringBuilder &to_string_builder(StringBuilder &string_builder) const = 0;