Move max_notification_message_id to NotificationInfo.

This commit is contained in:
levlam 2023-03-16 22:54:03 +03:00
parent b01ee666e9
commit ea2567f5d0
2 changed files with 40 additions and 29 deletions

View File

@ -5474,8 +5474,8 @@ void MessagesManager::Dialog::store(StorerT &storer) const {
notification_info != nullptr && notification_info->pinned_message_notification_message_id.is_valid(); notification_info != nullptr && notification_info->pinned_message_notification_message_id.is_valid();
bool has_last_pinned_message_id = last_pinned_message_id.is_valid(); bool has_last_pinned_message_id = last_pinned_message_id.is_valid();
bool has_flags2 = true; bool has_flags2 = true;
bool has_max_notification_message_id = bool has_max_notification_message_id = notification_info != nullptr &&
max_notification_message_id.is_valid() && max_notification_message_id > last_new_message_id; notification_info->max_notification_message_id.is_valid() && notification_info->max_notification_message_id > last_new_message_id;
bool has_folder_id = folder_id != FolderId(); bool has_folder_id = folder_id != FolderId();
bool has_pending_read_channel_inbox = pending_read_channel_inbox_pts != 0; bool has_pending_read_channel_inbox = pending_read_channel_inbox_pts != 0;
bool has_last_yet_unsent_message = last_message_id.is_valid() && last_message_id.is_yet_unsent(); bool has_last_yet_unsent_message = last_message_id.is_valid() && last_message_id.is_yet_unsent();
@ -5649,7 +5649,7 @@ void MessagesManager::Dialog::store(StorerT &storer) const {
store(last_pinned_message_id, storer); store(last_pinned_message_id, storer);
} }
if (has_max_notification_message_id) { if (has_max_notification_message_id) {
store(max_notification_message_id, storer); store(notification_info->max_notification_message_id, storer);
} }
if (has_folder_id) { if (has_folder_id) {
store(folder_id, storer); store(folder_id, storer);
@ -5947,7 +5947,7 @@ void MessagesManager::Dialog::parse(ParserT &parser) {
parse(last_pinned_message_id, parser); parse(last_pinned_message_id, parser);
} }
if (has_max_notification_message_id) { if (has_max_notification_message_id) {
parse(max_notification_message_id, parser); parse(add_dialog_notification_info(this)->max_notification_message_id, parser);
} }
if (has_folder_id) { if (has_folder_id) {
parse(folder_id, parser); parse(folder_id, parser);
@ -12695,9 +12695,11 @@ void MessagesManager::read_history_inbox(DialogId dialog_id, MessageId max_messa
unread_count = 0; unread_count = 0;
} }
LOG_IF(INFO, d->last_new_message_id.is_valid() && max_message_id > d->last_new_message_id && LOG_IF(
max_message_id > d->max_notification_message_id && max_message_id.is_server() && INFO,
dialog_id.get_type() != DialogType::Channel && !running_get_difference_) d->last_new_message_id.is_valid() && max_message_id > d->last_new_message_id &&
(d->notification_info != nullptr && max_message_id > d->notification_info->max_notification_message_id) &&
max_message_id.is_server() && dialog_id.get_type() != DialogType::Channel && !running_get_difference_)
<< "Receive read inbox update up to unknown " << max_message_id << " in " << dialog_id << " from " << source << "Receive read inbox update up to unknown " << max_message_id << " in " << dialog_id << " from " << source
<< ". Last new is " << d->last_new_message_id << ", unread_count = " << unread_count << ". Last new is " << d->last_new_message_id << ", unread_count = " << unread_count
<< ". Possible only for deleted incoming message"; << ". Possible only for deleted incoming message";
@ -21564,8 +21566,8 @@ Status MessagesManager::view_messages(DialogId dialog_id, vector<MessageId> mess
info->recently_viewed_messages[view_id] = message_id; info->recently_viewed_messages[view_id] = message_id;
} }
} else if (!message_id.is_yet_unsent() && message_id > max_message_id) { } else if (!message_id.is_yet_unsent() && message_id > max_message_id) {
if (message_id <= d->max_notification_message_id || message_id <= d->last_new_message_id || if ((d->notification_info != nullptr && message_id <= d->notification_info->max_notification_message_id) ||
message_id <= max_thread_message_id) { message_id <= d->last_new_message_id || message_id <= max_thread_message_id) {
max_message_id = message_id; max_message_id = message_id;
} }
} }
@ -26082,7 +26084,8 @@ MessageId MessagesManager::get_reply_to_message_id(Dialog *d, MessageId top_thre
if (m == nullptr || m->message_id.is_yet_unsent() || if (m == nullptr || m->message_id.is_yet_unsent() ||
(m->message_id.is_local() && d->dialog_id.get_type() != DialogType::SecretChat)) { (m->message_id.is_local() && d->dialog_id.get_type() != DialogType::SecretChat)) {
if (message_id.is_server() && d->dialog_id.get_type() != DialogType::SecretChat && if (message_id.is_server() && d->dialog_id.get_type() != DialogType::SecretChat &&
message_id > d->last_new_message_id && message_id <= d->max_notification_message_id) { message_id > d->last_new_message_id &&
(d->notification_info != nullptr && message_id <= d->notification_info->max_notification_message_id)) {
// allow to reply yet unreceived server message // allow to reply yet unreceived server message
return message_id; return message_id;
} }
@ -30404,17 +30407,21 @@ Result<MessagesManager::MessagePushNotificationInfo> MessagesManager::get_messag
return Status::Error("Ignore notification about sent scheduled message"); return Status::Error("Ignore notification about sent scheduled message");
} }
bool is_new_pinned = is_pinned && message_id.is_valid() && message_id > d->max_notification_message_id; bool is_new_pinned =
is_pinned && message_id.is_valid() &&
(d->notification_info == nullptr || message_id > d->notification_info->max_notification_message_id);
CHECK(!message_id.is_scheduled()); CHECK(!message_id.is_scheduled());
if (message_id.is_valid()) { if (message_id.is_valid()) {
if (message_id <= d->last_new_message_id) { if (message_id <= d->last_new_message_id) {
return Status::Error("Ignore notification about known message"); return Status::Error("Ignore notification about known message");
} }
if (!is_from_binlog && message_id == d->max_notification_message_id) { if (!is_from_binlog && d->notification_info != nullptr) {
return Status::Error("Ignore previously added message push notification"); if (message_id == d->notification_info->max_notification_message_id) {
} return Status::Error("Ignore previously added message push notification");
if (!is_from_binlog && message_id < d->max_notification_message_id) { }
return Status::Error("Ignore out of order message push notification"); if (message_id < d->notification_info->max_notification_message_id) {
return Status::Error("Ignore out of order message push notification");
}
} }
if (message_id <= d->last_read_inbox_message_id) { if (message_id <= d->last_read_inbox_message_id) {
return Status::Error("Ignore notification about read message"); return Status::Error("Ignore notification about read message");
@ -30477,13 +30484,16 @@ Result<MessagesManager::MessagePushNotificationInfo> MessagesManager::get_messag
return Status::Error("Can't assign notification group ID"); return Status::Error("Can't assign notification group ID");
} }
if (message_id.is_valid() && message_id > d->max_notification_message_id) { if (message_id.is_valid()) {
if (is_new_pinned) { auto notification_info = add_dialog_notification_info(d);
set_dialog_pinned_message_notification(d, contains_mention ? message_id : MessageId(), if (message_id > notification_info->max_notification_message_id) {
"get_message_push_notification_info"); if (is_new_pinned) {
set_dialog_pinned_message_notification(d, contains_mention ? message_id : MessageId(),
"get_message_push_notification_info");
}
notification_info->max_notification_message_id = message_id;
on_dialog_updated(dialog_id, "set_max_notification_message_id");
} }
d->max_notification_message_id = message_id;
on_dialog_updated(dialog_id, "set_max_notification_message_id");
} }
MessagePushNotificationInfo result; MessagePushNotificationInfo result;
@ -31519,7 +31529,7 @@ bool MessagesManager::add_new_message_notification(Dialog *d, Message *m, bool f
min_delay_ms = 1000; // 1 second min_delay_ms = 1000; // 1 second
} }
auto ringtone_id = get_dialog_notification_ringtone_id(settings_dialog_id, settings_dialog); auto ringtone_id = get_dialog_notification_ringtone_id(settings_dialog_id, settings_dialog);
bool is_silent = m->disable_notification || m->message_id <= d->max_notification_message_id; bool is_silent = m->disable_notification || m->message_id <= notification_info->max_notification_message_id;
send_closure_later(G()->notification_manager(), &NotificationManager::add_notification, notification_group_id, send_closure_later(G()->notification_manager(), &NotificationManager::add_notification, notification_group_id,
from_mentions ? NotificationGroupType::Mentions : NotificationGroupType::Messages, d->dialog_id, from_mentions ? NotificationGroupType::Mentions : NotificationGroupType::Messages, d->dialog_id,
m->date, settings_dialog_id, m->disable_notification, is_silent ? 0 : ringtone_id, min_delay_ms, m->date, settings_dialog_id, m->disable_notification, is_silent ? 0 : ringtone_id, min_delay_ms,
@ -31579,8 +31589,9 @@ void MessagesManager::remove_all_dialog_notifications(Dialog *d, bool from_menti
VLOG(notifications) << "Set max_removed_notification_id in " << group_info.group_id << '/' << d->dialog_id << " to " VLOG(notifications) << "Set max_removed_notification_id in " << group_info.group_id << '/' << d->dialog_id << " to "
<< group_info.last_notification_id << " from " << source; << group_info.last_notification_id << " from " << source;
group_info.max_removed_notification_id = group_info.last_notification_id; group_info.max_removed_notification_id = group_info.last_notification_id;
if (d->max_notification_message_id > group_info.max_removed_message_id) { if (d->notification_info->max_notification_message_id > group_info.max_removed_message_id) {
group_info.max_removed_message_id = d->max_notification_message_id.get_prev_server_message_id(); group_info.max_removed_message_id =
d->notification_info->max_notification_message_id.get_prev_server_message_id();
} }
if (!d->notification_info->pending_new_message_notifications.empty()) { if (!d->notification_info->pending_new_message_notifications.empty()) {
for (auto &it : d->notification_info->pending_new_message_notifications) { for (auto &it : d->notification_info->pending_new_message_notifications) {
@ -38218,10 +38229,10 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr<Message> &&last_datab
<< d->notification_info->mention_notification_group.max_removed_notification_id << "/" << d->notification_info->mention_notification_group.max_removed_notification_id << "/"
<< d->notification_info->mention_notification_group.max_removed_message_id << " and pinned " << d->notification_info->mention_notification_group.max_removed_message_id << " and pinned "
<< d->notification_info->pinned_message_notification_message_id; << d->notification_info->pinned_message_notification_message_id;
VLOG(notifications) << "In " << dialog_id << " have last_read_inbox_message_id = " << d->last_read_inbox_message_id
<< ", last_new_message_id = " << d->last_new_message_id
<< ", max_notification_message_id = " << d->notification_info->max_notification_message_id;
} }
VLOG(notifications) << "In " << dialog_id << " have last_read_inbox_message_id = " << d->last_read_inbox_message_id
<< ", last_new_message_id = " << d->last_new_message_id
<< ", max_notification_message_id = " << d->max_notification_message_id;
if (d->messages != nullptr) { if (d->messages != nullptr) {
if (d->messages->message_id != last_message_id || d->messages->left != nullptr || d->messages->right != nullptr) { if (d->messages->message_id != last_message_id || d->messages->left != nullptr || d->messages->right != nullptr) {

View File

@ -1288,6 +1288,7 @@ class MessagesManager final : public Actor {
NotificationGroupInfo mention_notification_group; NotificationGroupInfo mention_notification_group;
NotificationId new_secret_chat_notification_id; // secret chats only NotificationId new_secret_chat_notification_id; // secret chats only
MessageId pinned_message_notification_message_id; MessageId pinned_message_notification_message_id;
MessageId max_notification_message_id;
vector<std::pair<DialogId, MessageId>> pending_new_message_notifications; vector<std::pair<DialogId, MessageId>> pending_new_message_notifications;
vector<std::pair<DialogId, MessageId>> pending_new_mention_notifications; vector<std::pair<DialogId, MessageId>> pending_new_mention_notifications;
@ -1359,7 +1360,6 @@ class MessagesManager final : public Actor {
int32 delete_last_message_date = 0; int32 delete_last_message_date = 0;
int32 pending_last_message_date = 0; int32 pending_last_message_date = 0;
MessageId pending_last_message_id; MessageId pending_last_message_id;
MessageId max_notification_message_id;
MessageId last_edited_message_id; MessageId last_edited_message_id;
uint32 scheduled_messages_sync_generation = 0; uint32 scheduled_messages_sync_generation = 0;
uint32 last_repair_scheduled_messages_generation = 0; uint32 last_repair_scheduled_messages_generation = 0;