diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index acd39e05..19f1034b 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2165,8 +2165,9 @@ notificationGroupTypeSecretChat = NotificationGroupType; 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 Contains information about a notification @id Unique persistent identifier of this notification @date Notification date +//@is_silent True, if the notification was initially silent @type Notification type +notification id:int32 date:int32 is_silent:Bool type:NotificationType = Notification; //@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 diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index ced7d907..135a0947 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 635bca64..ba97d291 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -19412,7 +19412,7 @@ MessagesManager::MessageNotificationGroup MessagesManager::get_message_notificat result.type = NotificationGroupType::SecretChat; result.notifications.emplace_back(d->new_secret_chat_notification_id, td_->contacts_manager_->get_secret_chat_date(d->dialog_id.get_secret_chat_id()), - create_new_secret_chat_notification()); + false, create_new_secret_chat_notification()); } else { result.type = from_mentions ? NotificationGroupType::Mentions : NotificationGroupType::Messages; result.notifications = get_message_notifications_from_database_force( @@ -19476,7 +19476,8 @@ void MessagesManager::try_add_pinned_message_notification(Dialog *d, vectornotification_id, m->date, create_new_message_notification(message_id)); + res.emplace_back(m->notification_id, m->date, m->disable_notification, + create_new_message_notification(message_id)); while (pos > 0 && res[pos - 1].type->get_message_id().get() < message_id.get()) { std::swap(res[pos - 1], res[pos]); pos--; @@ -19590,7 +19591,8 @@ vector MessagesManager::get_message_notifications_from_database_fo if (is_correct) { // skip mention messages returned among unread messages - res.emplace_back(m->notification_id, m->date, create_new_message_notification(m->message_id)); + res.emplace_back(m->notification_id, m->date, m->disable_notification, + create_new_message_notification(m->message_id)); } else { remove_message_notification_id(d, m, true, false); on_message_changed(d, m, false, "get_message_notifications_from_database_force"); @@ -19694,7 +19696,7 @@ void MessagesManager::get_message_notifications_from_database(DialogId dialog_id vector notifications; if (!from_mentions && d->new_secret_chat_notification_id.get() < from_notification_id.get()) { notifications.emplace_back(d->new_secret_chat_notification_id, - td_->contacts_manager_->get_secret_chat_date(d->dialog_id.get_secret_chat_id()), + td_->contacts_manager_->get_secret_chat_date(d->dialog_id.get_secret_chat_id()), false, create_new_secret_chat_notification()); } return promise.set_value(std::move(notifications)); @@ -19833,7 +19835,8 @@ void MessagesManager::on_get_message_notifications_from_database(DialogId dialog if (is_correct) { // skip mention messages returned among unread messages - res.emplace_back(m->notification_id, m->date, create_new_message_notification(m->message_id)); + res.emplace_back(m->notification_id, m->date, m->disable_notification, + create_new_message_notification(m->message_id)); } else { remove_message_notification_id(d, m, true, false); on_message_changed(d, m, false, "on_get_message_notifications_from_database"); @@ -20262,7 +20265,7 @@ bool MessagesManager::add_new_message_notification(Dialog *d, Message *m, bool f bool is_silent = m->disable_notification || m->message_id.get() <= d->max_notification_message_id.get(); send_closure_later(G()->notification_manager(), &NotificationManager::add_notification, notification_group_id, from_mentions ? NotificationGroupType::Mentions : NotificationGroupType::Messages, d->dialog_id, - m->date, settings_dialog_id, is_silent, min_delay_ms, m->notification_id, + m->date, settings_dialog_id, m->disable_notification, is_silent, min_delay_ms, m->notification_id, create_new_message_notification(m->message_id), "add_new_message_notification"); return true; } @@ -24750,8 +24753,8 @@ void MessagesManager::force_create_dialog(DialogId dialog_id, const char *source 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, NotificationGroupType::SecretChat, dialog_id, date, dialog_id, - false, 0, d->new_secret_chat_notification_id, create_new_secret_chat_notification(), - "add_new_secret_chat_notification"); + false, false, 0, d->new_secret_chat_notification_id, + create_new_secret_chat_notification(), "add_new_secret_chat_notification"); } } } diff --git a/td/telegram/Notification.h b/td/telegram/Notification.h index 325f8f3e..f6b9e60a 100644 --- a/td/telegram/Notification.h +++ b/td/telegram/Notification.h @@ -20,10 +20,11 @@ class Notification { public: NotificationId notification_id; int32 date = 0; + bool is_silent = false; unique_ptr type; - Notification(NotificationId notification_id, int32 date, unique_ptr type) - : notification_id(notification_id), date(date), type(std::move(type)) { + Notification(NotificationId notification_id, int32 date, bool is_silent, unique_ptr type) + : notification_id(notification_id), date(date), is_silent(is_silent), type(std::move(type)) { } }; @@ -31,12 +32,13 @@ inline td_api::object_ptr get_notification_object(DialogId const Notification ¬ification) { CHECK(notification.type != nullptr); return td_api::make_object(notification.notification_id.get(), notification.date, + notification.is_silent, notification.type->get_notification_type_object(dialog_id)); } inline StringBuilder &operator<<(StringBuilder &sb, const Notification ¬ification) { return sb << "notification[" << notification.notification_id << ", " << notification.date << ", " - << *notification.type << ']'; + << notification.is_silent << ", " << *notification.type << ']'; } } // namespace td diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index 2b93728b..25ce0870 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -842,8 +842,9 @@ int32 NotificationManager::get_notification_delay_ms(DialogId dialog_id, const P void NotificationManager::add_notification(NotificationGroupId group_id, NotificationGroupType group_type, DialogId dialog_id, int32 date, DialogId notification_settings_dialog_id, - bool is_silent, int32 min_delay_ms, NotificationId notification_id, - unique_ptr type, const char *source) { + bool initial_is_silent, bool is_silent, int32 min_delay_ms, + NotificationId notification_id, unique_ptr type, + const char *source) { if (is_disabled() || max_notification_group_count_ == 0) { on_notification_removed(notification_id); return; @@ -890,6 +891,7 @@ void NotificationManager::add_notification(NotificationGroupId group_id, Notific PendingNotification notification; notification.date = date; notification.settings_dialog_id = notification_settings_dialog_id; + notification.initial_is_silent = initial_is_silent; notification.is_silent = is_silent; notification.notification_id = notification_id; notification.type = std::move(type); @@ -1385,7 +1387,7 @@ bool NotificationManager::do_flush_pending_notifications(NotificationGroupKey &g added_notifications.reserve(pending_notifications.size()); for (auto &pending_notification : pending_notifications) { Notification notification(pending_notification.notification_id, pending_notification.date, - std::move(pending_notification.type)); + pending_notification.initial_is_silent, std::move(pending_notification.type)); added_notifications.push_back(get_notification_object(group_key.dialog_id, notification)); if (added_notifications.back()->type_ == nullptr) { added_notifications.pop_back(); @@ -1513,7 +1515,7 @@ void NotificationManager::flush_pending_notifications(NotificationGroupId group_ group.total_count += narrow_cast(group.pending_notifications.size()); for (auto &pending_notification : group.pending_notifications) { group.notifications.emplace_back(pending_notification.notification_id, pending_notification.date, - std::move(pending_notification.type)); + pending_notification.initial_is_silent, std::move(pending_notification.type)); } } else { if (!was_updated) { @@ -2308,8 +2310,8 @@ void NotificationManager::add_call_notification(DialogId dialog_id, CallId call_ } active_notifications.push_back(ActiveCallNotification{call_id, notification_id}); - add_notification(group_id, NotificationGroupType::Calls, dialog_id, G()->unix_time() + 120, dialog_id, false, 0, - notification_id, create_new_call_notification(call_id), "add_call_notification"); + add_notification(group_id, NotificationGroupType::Calls, dialog_id, G()->unix_time() + 120, dialog_id, false, false, + 0, notification_id, create_new_call_notification(call_id), "add_call_notification"); } void NotificationManager::remove_call_notification(DialogId dialog_id, CallId call_id) { @@ -3375,9 +3377,9 @@ Status NotificationManager::process_push_notification_payload(string payload, bo } else { bool is_silent = has_json_object_field(custom, "silent"); add_message_push_notification(dialog_id, MessageId(server_message_id), random_id, sender_user_id, - std::move(sender_name), sent_date, contains_mention, is_silent, std::move(loc_key), - std::move(arg), std::move(attached_photo), std::move(attached_document), - NotificationId(), 0, std::move(promise)); + std::move(sender_name), sent_date, contains_mention, is_silent, is_silent, + std::move(loc_key), std::move(arg), std::move(attached_photo), + std::move(attached_document), NotificationId(), 0, std::move(promise)); } return Status::OK(); } @@ -3499,8 +3501,8 @@ class NotificationManager::AddMessagePushNotificationLogEvent { void NotificationManager::add_message_push_notification(DialogId dialog_id, MessageId message_id, int64 random_id, UserId sender_user_id, string sender_name, int32 date, - bool contains_mention, bool is_silent, string loc_key, - string arg, Photo photo, Document document, + bool contains_mention, bool initial_is_silent, bool is_silent, + string loc_key, string arg, Photo photo, Document document, NotificationId notification_id, uint64 logevent_id, Promise promise) { auto is_pinned = begins_with(loc_key, "PINNED_"); @@ -3560,8 +3562,8 @@ void NotificationManager::add_message_push_notification(DialogId dialog_id, Mess if (logevent_id == 0 && G()->parameters().use_message_db) { AddMessagePushNotificationLogEvent logevent{ - dialog_id, message_id, random_id, sender_user_id, sender_name, date, contains_mention, - is_silent, loc_key, arg, photo, document, notification_id}; + dialog_id, message_id, random_id, sender_user_id, sender_name, date, contains_mention, + initial_is_silent, loc_key, arg, photo, document, notification_id}; auto storer = LogEventStorerImpl(logevent); logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::AddMessagePushNotification, storer); } @@ -3584,7 +3586,8 @@ void NotificationManager::add_message_push_notification(DialogId dialog_id, Mess << " with arg " << arg << ", photo " << photo << " and document " << document << " to " << group_id << " of type " << group_type << " with settings from " << settings_dialog_id; - add_notification(group_id, group_type, dialog_id, date, settings_dialog_id, is_silent, 0, notification_id, + add_notification(group_id, group_type, dialog_id, date, settings_dialog_id, initial_is_silent, is_silent, 0, + notification_id, create_new_push_message_notification(sender_user_id, message_id, std::move(loc_key), std::move(arg), std::move(photo), std::move(document)), "add_message_push_notification"); @@ -4030,9 +4033,9 @@ void NotificationManager::on_binlog_events(vector &&events) { add_message_push_notification( log_event.dialog_id_, log_event.message_id_, log_event.random_id_, log_event.sender_user_id_, - log_event.sender_name_, log_event.date_, log_event.contains_mention_, true, log_event.loc_key_, - log_event.arg_, log_event.photo_, log_event.document_, log_event.notification_id_, event.id_, - PromiseCreator::lambda([](Result result) { + log_event.sender_name_, log_event.date_, log_event.contains_mention_, log_event.is_silent_, true, + log_event.loc_key_, log_event.arg_, log_event.photo_, log_event.document_, log_event.notification_id_, + event.id_, PromiseCreator::lambda([](Result result) { if (result.is_error() && result.error().code() != 200 && result.error().code() != 406) { LOG(ERROR) << "Receive error " << result.error() << ", while processing message push notification"; } diff --git a/td/telegram/NotificationManager.h b/td/telegram/NotificationManager.h index 103d0f4c..d0f59079 100644 --- a/td/telegram/NotificationManager.h +++ b/td/telegram/NotificationManager.h @@ -65,8 +65,9 @@ class NotificationManager : public Actor { void load_group_force(NotificationGroupId group_id); void add_notification(NotificationGroupId group_id, NotificationGroupType group_type, DialogId dialog_id, int32 date, - DialogId notification_settings_dialog_id, bool is_silent, int32 min_delay_ms, - NotificationId notification_id, unique_ptr type, const char *source); + DialogId notification_settings_dialog_id, bool initial_is_silent, bool is_silent, + int32 min_delay_ms, NotificationId notification_id, unique_ptr type, + const char *source); void edit_notification(NotificationGroupId group_id, NotificationId notification_id, unique_ptr type); @@ -154,6 +155,7 @@ class NotificationManager : public Actor { struct PendingNotification { int32 date = 0; DialogId settings_dialog_id; + bool initial_is_silent = false; bool is_silent = false; NotificationId notification_id; unique_ptr type; @@ -303,8 +305,8 @@ class NotificationManager : public Actor { Status process_push_notification_payload(string payload, bool was_encrypted, Promise &promise); void add_message_push_notification(DialogId dialog_id, MessageId message_id, int64 random_id, UserId sender_user_id, - string sender_name, int32 date, bool contains_mention, bool is_silent, - string loc_key, string arg, Photo photo, Document document, + string sender_name, int32 date, bool contains_mention, bool initial_is_silent, + bool is_silent, string loc_key, string arg, Photo photo, Document document, NotificationId notification_id, uint64 logevent_id, Promise promise); void edit_message_push_notification(DialogId dialog_id, MessageId message_id, int32 edit_date, string loc_key,