Do not delay notification removal updates requested by the user.

GitOrigin-RevId: 7ca24f9da47239c9596e0bec1143b15ae8327bac
This commit is contained in:
levlam 2019-03-27 01:07:32 +03:00
parent 1e1b24dfb3
commit 5d00a38046
4 changed files with 35 additions and 24 deletions

View File

@ -8507,7 +8507,7 @@ void MessagesManager::set_dialog_last_read_inbox_message_id(Dialog *d, MessageId
}
send_closure_later(G()->notification_manager(), &NotificationManager::remove_notification_group,
d->message_notification_group.group_id, NotificationId(), d->last_read_inbox_message_id,
total_count, Promise<Unit>());
total_count, Slice(source) == Slice("view_messages"), Promise<Unit>());
}
if (d->mention_notification_group.group_id.is_valid() && d->pinned_message_notification_message_id.is_valid() &&
@ -10259,7 +10259,7 @@ void MessagesManager::remove_dialog_mention_notifications(Dialog *d) {
if (m->notification_id.is_valid() && is_message_notification_active(d, m) &&
is_from_mention_notification_group(d, m)) {
send_closure_later(G()->notification_manager(), &NotificationManager::remove_notification, notification_group_id,
m->notification_id, false, Promise<Unit>());
m->notification_id, false, true, Promise<Unit>());
}
}
@ -10271,7 +10271,7 @@ void MessagesManager::remove_dialog_mention_notifications(Dialog *d) {
if (m != nullptr && m->notification_id.is_valid() && is_message_notification_active(d, m)) {
CHECK(is_from_mention_notification_group(d, m));
send_closure_later(G()->notification_manager(), &NotificationManager::remove_notification,
notification_group_id, m->notification_id, false, Promise<Unit>());
notification_group_id, m->notification_id, false, true, Promise<Unit>());
}
}
}
@ -10829,7 +10829,7 @@ void MessagesManager::remove_message_notification_id(Dialog *d, Message *m, bool
if (is_permanent) {
if (had_active_notification) {
send_closure_later(G()->notification_manager(), &NotificationManager::remove_notification, group_info.group_id,
notification_id, true, Promise<Unit>());
notification_id, true, true, Promise<Unit>());
}
// on_message_changed will be called by the caller
@ -10852,7 +10852,7 @@ void MessagesManager::remove_new_secret_chat_notification(Dialog *d, bool is_per
if (is_permanent) {
CHECK(d->message_notification_group.group_id.is_valid());
send_closure_later(G()->notification_manager(), &NotificationManager::remove_notification,
d->message_notification_group.group_id, notification_id, true, Promise<Unit>());
d->message_notification_group.group_id, notification_id, true, true, Promise<Unit>());
}
}
@ -19054,7 +19054,7 @@ void MessagesManager::remove_all_dialog_notifications(Dialog *d, NotificationGro
<< group_info.last_notification_id << " from " << source;
group_info.max_removed_notification_id = group_info.last_notification_id;
send_closure_later(G()->notification_manager(), &NotificationManager::remove_notification_group,
group_info.group_id, group_info.last_notification_id, MessageId(), 0, Promise<Unit>());
group_info.group_id, group_info.last_notification_id, MessageId(), 0, true, Promise<Unit>());
if (d->new_secret_chat_notification_id.is_valid() && &group_info == &d->message_notification_group) {
remove_new_secret_chat_notification(d, false);
} else {
@ -19088,7 +19088,7 @@ void MessagesManager::remove_message_dialog_notifications(Dialog *d, MessageId m
}
send_closure_later(G()->notification_manager(), &NotificationManager::remove_notification_group, group_info.group_id,
NotificationId(), max_notification_message_id, 0, Promise<Unit>());
NotificationId(), max_notification_message_id, 0, true, Promise<Unit>());
}
void MessagesManager::send_update_message_send_succeeded(Dialog *d, MessageId old_message_id, const Message *m) const {
@ -22169,7 +22169,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
}
send_closure_later(G()->notification_manager(), &NotificationManager::remove_notification,
d->mention_notification_group.group_id, notification_id, false, Promise<Unit>());
d->mention_notification_group.group_id, notification_id, false, false, Promise<Unit>());
on_message_changed(d, message.get(), false, "remove_mention_notification");
}
@ -22581,7 +22581,7 @@ void MessagesManager::delete_message_from_database(Dialog *d, MessageId message_
}
if (is_message_notification_active(d, m)) {
send_closure_later(G()->notification_manager(), &NotificationManager::remove_notification, group_info.group_id,
m->notification_id, true, Promise<Unit>());
m->notification_id, true, false, Promise<Unit>());
}
}
}

View File

@ -1502,7 +1502,7 @@ void NotificationManager::edit_notification(NotificationGroupId group_id, Notifi
void NotificationManager::on_notifications_removed(
NotificationGroups::iterator &&group_it, vector<td_api::object_ptr<td_api::notification>> &&added_notifications,
vector<int32> &&removed_notification_ids) {
vector<int32> &&removed_notification_ids, bool force_update) {
VLOG(notifications) << "In on_notifications_removed for " << group_it->first.group_id << " with "
<< added_notifications.size() << " added notifications and " << removed_notification_ids.size()
<< " removed notifications, new total_count = " << group_it->second.total_count;
@ -1567,6 +1567,12 @@ void NotificationManager::on_notifications_removed(
group_it->second = std::move(group);
}
if (force_update) {
auto id = group_key.group_id.get();
flush_pending_updates_timeout_.cancel_timeout(id);
flush_pending_updates(id, "on_notifications_removed");
}
if (last_loaded_notification_group_key_ < last_group_key) {
load_message_notification_groups_from_database(td::max(static_cast<int32>(max_notification_group_count_), 10) / 2,
true);
@ -1620,7 +1626,7 @@ void NotificationManager::remove_added_notifications_from_pending_updates(
}
void NotificationManager::remove_notification(NotificationGroupId group_id, NotificationId notification_id,
bool is_permanent, Promise<Unit> &&promise) {
bool is_permanent, bool force_update, Promise<Unit> &&promise) {
if (!group_id.is_valid()) {
return promise.set_error(Status::Error(400, "Notification group identifier is invalid"));
}
@ -1632,7 +1638,8 @@ void NotificationManager::remove_notification(NotificationGroupId group_id, Noti
return promise.set_value(Unit());
}
VLOG(notifications) << "Remove " << notification_id << " from " << group_id;
VLOG(notifications) << "Remove " << notification_id << " from " << group_id
<< " with force_update = " << force_update;
auto group_it = get_group_force(group_id);
if (group_it == groups_.end()) {
@ -1698,7 +1705,8 @@ void NotificationManager::remove_notification(NotificationGroupId group_id, Noti
}
if (is_total_count_changed || !removed_notification_ids.empty()) {
on_notifications_removed(std::move(group_it), std::move(added_notifications), std::move(removed_notification_ids));
on_notifications_removed(std::move(group_it), std::move(added_notifications), std::move(removed_notification_ids),
force_update);
}
remove_added_notifications_from_pending_updates(
@ -1710,7 +1718,7 @@ void NotificationManager::remove_notification(NotificationGroupId group_id, Noti
}
void NotificationManager::remove_notification_group(NotificationGroupId group_id, NotificationId max_notification_id,
MessageId max_message_id, int32 new_total_count,
MessageId max_message_id, int32 new_total_count, bool force_update,
Promise<Unit> &&promise) {
if (!group_id.is_valid()) {
return promise.set_error(Status::Error(400, "Group identifier is invalid"));
@ -1724,7 +1732,7 @@ void NotificationManager::remove_notification_group(NotificationGroupId group_id
}
VLOG(notifications) << "Remove " << group_id << " up to " << max_notification_id << " or " << max_message_id
<< " with new_total_count = " << new_total_count;
<< " with new_total_count = " << new_total_count << " and force_update = " << force_update;
auto group_it = get_group_force(group_id);
if (group_it == groups_.end()) {
@ -1760,7 +1768,8 @@ void NotificationManager::remove_notification_group(NotificationGroupId group_id
if (new_total_count != -1) {
new_total_count -= static_cast<int32>(group_it->second.pending_notifications.size());
if (new_total_count < 0) {
LOG(ERROR) << "Have wrong new_total_count " << new_total_count;
LOG(ERROR) << "Have wrong new_total_count " << new_total_count << " + "
<< group_it->second.pending_notifications.size();
}
}
@ -1802,7 +1811,7 @@ void NotificationManager::remove_notification_group(NotificationGroupId group_id
if (new_total_count != -1 || !removed_notification_ids.empty()) {
on_notifications_removed(std::move(group_it), vector<td_api::object_ptr<td_api::notification>>(),
std::move(removed_notification_ids));
std::move(removed_notification_ids), force_update);
} else {
VLOG(notifications) << "Have new_total_count = " << new_total_count << " and " << removed_notification_ids.size()
<< " removed notifications";
@ -1859,7 +1868,8 @@ void NotificationManager::set_notification_total_count(NotificationGroupId group
VLOG(notifications) << "Set total_count in " << group_id << " to " << new_total_count;
group_it->second.total_count = new_total_count;
on_notifications_removed(std::move(group_it), vector<td_api::object_ptr<td_api::notification>>(), vector<int32>());
on_notifications_removed(std::move(group_it), vector<td_api::object_ptr<td_api::notification>>(), vector<int32>(),
false);
}
vector<MessageId> NotificationManager::get_notification_group_message_ids(NotificationGroupId group_id) {
@ -1978,7 +1988,7 @@ void NotificationManager::remove_call_notification(DialogId dialog_id, CallId ca
auto &active_notifications = active_call_notifications_[dialog_id];
for (auto it = active_notifications.begin(); it != active_notifications.end(); ++it) {
if (it->call_id == call_id) {
remove_notification(group_id, it->notification_id, true, Promise<Unit>());
remove_notification(group_id, it->notification_id, true, true, Promise<Unit>());
active_notifications.erase(it);
if (active_notifications.empty()) {
VLOG(notifications) << "Reuse call " << group_id;

View File

@ -69,10 +69,11 @@ class NotificationManager : public Actor {
unique_ptr<NotificationType> type);
void remove_notification(NotificationGroupId group_id, NotificationId notification_id, bool is_permanent,
Promise<Unit> &&promise);
bool force_update, Promise<Unit> &&promise);
void remove_notification_group(NotificationGroupId group_id, NotificationId max_notification_id,
MessageId max_message_id, int32 new_total_count, Promise<Unit> &&promise);
MessageId max_message_id, int32 new_total_count, bool force_update,
Promise<Unit> &&promise);
void set_notification_total_count(NotificationGroupId group_id, int32 new_total_count);
@ -241,7 +242,7 @@ class NotificationManager : public Actor {
void on_notifications_removed(NotificationGroups::iterator &&group_it,
vector<td_api::object_ptr<td_api::notification>> &&added_notifications,
vector<int32> &&removed_notification_ids);
vector<int32> &&removed_notification_ids, bool force_update);
void remove_added_notifications_from_pending_updates(
NotificationGroupId group_id,

View File

@ -5252,14 +5252,14 @@ void Td::on_request(uint64 id, const td_api::removeNotification &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
notification_manager_->remove_notification(NotificationGroupId(request.notification_group_id_),
NotificationId(request.notification_id_), false, std::move(promise));
NotificationId(request.notification_id_), false, true, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::removeNotificationGroup &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
notification_manager_->remove_notification_group(NotificationGroupId(request.notification_group_id_),
NotificationId(request.max_notification_id_), MessageId(), -1,
NotificationId(request.max_notification_id_), MessageId(), -1, true,
std::move(promise));
}