Return back notification.is_silent.

This commit is contained in:
levlam 2022-05-03 16:09:40 +03:00
parent 4b7dab920e
commit fb1efdbba8
5 changed files with 55 additions and 38 deletions

View File

@ -3173,8 +3173,8 @@ notificationSounds notification_sounds:vector<notificationSound> = NotificationS
//@description Contains information about a notification @id Unique persistent identifier of this notification @date Notification date
//@sound_id Identifier of the notification sound to be played; 0 if sound is disabled @type Notification type
notification id:int32 date:int32 sound_id:int64 type:NotificationType = Notification;
//@is_silent True, if the notification was explicitly sent without sound @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

View File

@ -29761,7 +29761,7 @@ bool MessagesManager::add_new_message_notification(Dialog *d, Message *m, bool f
DialogId settings_dialog_id = d->dialog_id;
Dialog *settings_dialog = d;
if (m->contains_mention && !m->is_mention_notification_disabled) {
if (is_from_mention_notification_group(d, m)) {
// have a mention, so use notification settings from the dialog with the sender
auto sender_dialog_id = get_message_sender(m);
if (sender_dialog_id.is_valid()) {
@ -29877,9 +29877,9 @@ bool MessagesManager::add_new_message_notification(Dialog *d, Message *m, bool f
bool is_silent = m->disable_notification || m->message_id <= d->max_notification_message_id;
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, m->disable_notification ? 0 : ringtone_id,
is_silent ? 0 : ringtone_id, min_delay_ms, m->notification_id,
create_new_message_notification(m->message_id), "add_new_message_notification");
m->date, settings_dialog_id, m->disable_notification, is_silent ? 0 : ringtone_id, min_delay_ms,
m->notification_id, create_new_message_notification(m->message_id),
"add_new_message_notification");
return true;
}
@ -35733,7 +35733,7 @@ void MessagesManager::force_create_dialog(DialogId dialog_id, const char *source
auto ringtone_id = get_dialog_notification_ringtone_id(dialog_id, d);
send_closure_later(G()->notification_manager(), &NotificationManager::add_notification,
notification_group_id, NotificationGroupType::SecretChat, dialog_id, date, dialog_id,
ringtone_id, ringtone_id, 0, d->new_secret_chat_notification_id,
false, ringtone_id, 0, d->new_secret_chat_notification_id,
create_new_secret_chat_notification(), "add_new_secret_chat_notification");
}
}

View File

@ -20,11 +20,14 @@ class Notification {
public:
NotificationId notification_id;
int32 date = 0;
int64 ringtone_id = -1;
bool disable_notification = false;
unique_ptr<NotificationType> type;
Notification(NotificationId notification_id, int32 date, int64 ringtone_id, unique_ptr<NotificationType> type)
: notification_id(notification_id), date(date), ringtone_id(ringtone_id), type(std::move(type)) {
Notification(NotificationId notification_id, int32 date, bool disable_notification, unique_ptr<NotificationType> type)
: notification_id(notification_id)
, date(date)
, disable_notification(disable_notification)
, type(std::move(type)) {
}
};
@ -32,13 +35,13 @@ inline td_api::object_ptr<td_api::notification> get_notification_object(DialogId
const Notification &notification) {
CHECK(notification.type != nullptr);
return td_api::make_object<td_api::notification>(notification.notification_id.get(), notification.date,
notification.ringtone_id,
notification.disable_notification,
notification.type->get_notification_type_object(dialog_id));
}
inline StringBuilder &operator<<(StringBuilder &sb, const Notification &notification) {
return sb << "notification[" << notification.notification_id << ", " << notification.date << ", "
<< notification.ringtone_id << ", " << *notification.type << ']';
<< notification.disable_notification << ", " << *notification.type << ']';
}
} // namespace td

View File

@ -855,7 +855,7 @@ 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,
int64 initial_ringtone_id, int64 ringtone_id, int32 min_delay_ms,
bool disable_notification, int64 ringtone_id, int32 min_delay_ms,
NotificationId notification_id, unique_ptr<NotificationType> type,
const char *source) {
if (is_disabled() || max_notification_group_count_ == 0) {
@ -904,8 +904,8 @@ void NotificationManager::add_notification(NotificationGroupId group_id, Notific
PendingNotification notification;
notification.date = date;
notification.settings_dialog_id = notification_settings_dialog_id;
notification.initial_ringtone_id = initial_ringtone_id;
notification.ringtone_id = ringtone_id;
notification.disable_notification = disable_notification;
notification.ringtone_id = disable_notification ? 0 : ringtone_id;
notification.notification_id = notification_id;
notification.type = std::move(type);
@ -1392,7 +1392,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,
pending_notification.initial_ringtone_id, std::move(pending_notification.type));
pending_notification.disable_notification, std::move(pending_notification.type));
added_notifications.push_back(get_notification_object(group_key.dialog_id, notification));
CHECK(added_notifications.back()->type_ != nullptr);
@ -1523,7 +1523,7 @@ void NotificationManager::flush_pending_notifications(NotificationGroupId group_
group.total_count += narrow_cast<int32>(group.pending_notifications.size());
for (auto &pending_notification : group.pending_notifications) {
group.notifications.emplace_back(pending_notification.notification_id, pending_notification.date,
pending_notification.initial_ringtone_id, std::move(pending_notification.type));
pending_notification.disable_notification, std::move(pending_notification.type));
}
} else {
if (!was_updated) {
@ -2318,8 +2318,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, 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, -1, 0,
notification_id, create_new_call_notification(call_id), "add_call_notification");
}
void NotificationManager::remove_call_notification(DialogId dialog_id, CallId call_id) {
@ -3437,16 +3437,19 @@ Status NotificationManager::process_push_notification_payload(string payload, bo
std::move(promise));
} else {
bool is_from_scheduled = has_json_object_field(custom, "schedule");
bool disable_notification = false;
int64 ringtone_id = -1;
if (has_json_object_field(custom, "silent")) {
disable_notification = true;
ringtone_id = 0;
} else if (has_json_object_field(custom, "ringtone")) {
TRY_RESULT_ASSIGN(ringtone_id, get_json_object_long_field(custom, "ringtone"));
}
add_message_push_notification(dialog_id, MessageId(server_message_id), random_id, sender_user_id, sender_dialog_id,
std::move(sender_name), sent_date, is_from_scheduled, contains_mention, ringtone_id,
ringtone_id, 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, is_from_scheduled, contains_mention,
disable_notification, ringtone_id, std::move(loc_key), std::move(arg),
std::move(attached_photo), std::move(attached_document), NotificationId(), 0,
std::move(promise));
}
return Status::OK();
}
@ -3462,6 +3465,7 @@ class NotificationManager::AddMessagePushNotificationLogEvent {
int32 date_;
bool is_from_scheduled_;
bool contains_mention_;
bool disable_notification_;
int64 ringtone_id_;
string loc_key_;
string arg_;
@ -3479,11 +3483,10 @@ class NotificationManager::AddMessagePushNotificationLogEvent {
bool has_photo = !photo_.is_empty();
bool has_document = !document_.empty();
bool has_sender_dialog_id = sender_dialog_id_.is_valid();
bool is_silent = ringtone_id_ == 0;
bool has_ringtone_id = !is_silent && ringtone_id_ != -1;
bool has_ringtone_id = !disable_notification_ && ringtone_id_ != -1;
BEGIN_STORE_FLAGS();
STORE_FLAG(contains_mention_);
STORE_FLAG(is_silent);
STORE_FLAG(disable_notification_);
STORE_FLAG(has_message_id);
STORE_FLAG(has_random_id);
STORE_FLAG(has_sender);
@ -3538,11 +3541,10 @@ class NotificationManager::AddMessagePushNotificationLogEvent {
bool has_photo;
bool has_document;
bool has_sender_dialog_id;
bool is_silent;
bool has_ringtone_id;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(contains_mention_);
PARSE_FLAG(is_silent);
PARSE_FLAG(disable_notification_);
PARSE_FLAG(has_message_id);
PARSE_FLAG(has_random_id);
PARSE_FLAG(has_sender);
@ -3587,7 +3589,7 @@ class NotificationManager::AddMessagePushNotificationLogEvent {
if (has_ringtone_id) {
td::parse(ringtone_id_, parser);
} else {
ringtone_id_ = is_silent ? 0 : -1;
ringtone_id_ = disable_notification_ ? 0 : -1;
}
}
};
@ -3595,7 +3597,7 @@ class NotificationManager::AddMessagePushNotificationLogEvent {
void NotificationManager::add_message_push_notification(DialogId dialog_id, MessageId message_id, int64 random_id,
UserId sender_user_id, DialogId sender_dialog_id,
string sender_name, int32 date, bool is_from_scheduled,
bool contains_mention, int64 initial_ringtone_id,
bool contains_mention, bool disable_notification,
int64 ringtone_id, string loc_key, string arg, Photo photo,
Document document, NotificationId notification_id,
uint64 log_event_id, Promise<Unit> promise) {
@ -3659,10 +3661,22 @@ void NotificationManager::add_message_push_notification(DialogId dialog_id, Mess
}
if (log_event_id == 0 && G()->parameters().use_message_db) {
AddMessagePushNotificationLogEvent log_event{
dialog_id, message_id, random_id, sender_user_id, sender_dialog_id, sender_name,
date, is_from_scheduled, contains_mention, initial_ringtone_id, loc_key, arg,
photo, document, notification_id};
AddMessagePushNotificationLogEvent log_event{dialog_id,
message_id,
random_id,
sender_user_id,
sender_dialog_id,
sender_name,
date,
is_from_scheduled,
contains_mention,
disable_notification,
ringtone_id,
loc_key,
arg,
photo,
document,
notification_id};
log_event_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::AddMessagePushNotification,
get_log_event_storer(log_event));
}
@ -3690,7 +3704,7 @@ void NotificationManager::add_message_push_notification(DialogId dialog_id, Mess
<< group_type << " with settings from " << settings_dialog_id;
add_notification(
group_id, group_type, dialog_id, date, settings_dialog_id, initial_ringtone_id, ringtone_id, 0, notification_id,
group_id, group_type, dialog_id, date, settings_dialog_id, disable_notification, ringtone_id, 0, notification_id,
create_new_push_message_notification(sender_user_id, sender_dialog_id, sender_name, is_outgoing, message_id,
std::move(loc_key), std::move(arg), std::move(photo), std::move(document)),
"add_message_push_notification");
@ -4143,7 +4157,7 @@ void NotificationManager::on_binlog_events(vector<BinlogEvent> &&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_dialog_id_, log_event.sender_name_, log_event.date_, log_event.is_from_scheduled_,
log_event.contains_mention_, log_event.ringtone_id_, 0, log_event.loc_key_, log_event.arg_,
log_event.contains_mention_, log_event.disable_notification_, 0, log_event.loc_key_, log_event.arg_,
log_event.photo_, log_event.document_, log_event.notification_id_, event.id_,
PromiseCreator::lambda([](Result<Unit> result) {
if (result.is_error() && result.error().code() != 200 && result.error().code() != 406) {

View File

@ -67,7 +67,7 @@ class NotificationManager final : 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, int64 initial_ringtone_id, int64 ringtone_id,
DialogId notification_settings_dialog_id, bool disable_notification, int64 ringtone_id,
int32 min_delay_ms, NotificationId notification_id, unique_ptr<NotificationType> type,
const char *source);
@ -161,7 +161,7 @@ class NotificationManager final : public Actor {
struct PendingNotification {
int32 date = 0;
DialogId settings_dialog_id;
int64 initial_ringtone_id = -1;
bool disable_notification = false;
int64 ringtone_id = -1;
NotificationId notification_id;
unique_ptr<NotificationType> type;
@ -313,7 +313,7 @@ class NotificationManager final : public Actor {
void add_message_push_notification(DialogId dialog_id, MessageId message_id, int64 random_id, UserId sender_user_id,
DialogId sender_dialog_id, string sender_name, int32 date, bool is_from_scheduled,
bool contains_mention, int64 initial_ringtone_id, int64 ringtone_id,
bool contains_mention, bool disable_notification, int64 ringtone_id,
string loc_key, string arg, Photo photo, Document document,
NotificationId notification_id, uint64 log_event_id, Promise<Unit> promise);