Call update_dialog_lists when a dialog can move in or out filter list.

GitOrigin-RevId: 58af40a3a37797c1b9f84c7db4a1dba20fda513f
This commit is contained in:
levlam 2020-05-22 03:09:37 +03:00
parent 0edc0721ef
commit a619ff4b87

View File

@ -6979,7 +6979,6 @@ void MessagesManager::update_dialog_unmute_timeout(Dialog *d, bool old_use_defau
if (old_mute_until != -1 && need_unread_counter(d->order)) { if (old_mute_until != -1 && need_unread_counter(d->order)) {
auto unread_count = d->server_unread_count + d->local_unread_count; auto unread_count = d->server_unread_count + d->local_unread_count;
if (unread_count != 0 || d->is_marked_as_unread) {
if (old_use_default || new_use_default) { if (old_use_default || new_use_default) {
auto scope_mute_until = get_scope_mute_until(d->dialog_id); auto scope_mute_until = get_scope_mute_until(d->dialog_id);
if (old_use_default) { if (old_use_default) {
@ -6990,6 +6989,7 @@ void MessagesManager::update_dialog_unmute_timeout(Dialog *d, bool old_use_defau
} }
} }
if ((old_mute_until != 0) != (new_mute_until != 0)) { if ((old_mute_until != 0) != (new_mute_until != 0)) {
if (unread_count != 0 || d->is_marked_as_unread) {
for (auto &list : get_dialog_lists(d)) { for (auto &list : get_dialog_lists(d)) {
if (unread_count != 0 && list.is_message_unread_count_inited_) { if (unread_count != 0 && list.is_message_unread_count_inited_) {
int32 delta = old_mute_until != 0 ? -unread_count : unread_count; int32 delta = old_mute_until != 0 ? -unread_count : unread_count;
@ -7006,6 +7006,9 @@ void MessagesManager::update_dialog_unmute_timeout(Dialog *d, bool old_use_defau
} }
} }
} }
if (!dialog_filters_.empty()) {
update_dialog_lists(d, get_dialog_orders(d), true, false, "update_dialog_unmute_timeout");
}
} }
} }
} }
@ -7029,10 +7032,11 @@ void MessagesManager::update_scope_unmute_timeout(NotificationSettingsScope scop
dialog_unmute_timeout_.cancel_timeout(static_cast<int64>(scope) + 1); dialog_unmute_timeout_.cancel_timeout(static_cast<int64>(scope) + 1);
} }
if (old_mute_until != -1 && !td_->auth_manager_->is_bot() && G()->parameters().use_message_db) { if (old_mute_until != -1) {
auto was_muted = old_mute_until != 0; auto was_muted = old_mute_until != 0;
auto is_muted = new_mute_until != 0; auto is_muted = new_mute_until != 0;
if (was_muted != is_muted) { if (was_muted != is_muted) {
if (G()->parameters().use_message_db) {
std::unordered_map<DialogListId, int32, DialogListIdHash> delta; std::unordered_map<DialogListId, int32, DialogListIdHash> delta;
std::unordered_map<DialogListId, int32, DialogListIdHash> total_count; std::unordered_map<DialogListId, int32, DialogListIdHash> total_count;
std::unordered_map<DialogListId, int32, DialogListIdHash> marked_count; std::unordered_map<DialogListId, int32, DialogListIdHash> marked_count;
@ -7080,6 +7084,17 @@ void MessagesManager::update_scope_unmute_timeout(NotificationSettingsScope scop
} }
} }
} }
if (!dialog_filters_.empty()) {
for (auto &dialog : dialogs_) {
Dialog *d = dialog.second.get();
if (d->order != DEFAULT_ORDER && d->notification_settings.use_default_mute_until &&
get_dialog_notification_setting_scope(d->dialog_id) == scope) {
update_dialog_lists(d, get_dialog_orders(d), true, false, "update_scope_unmute_timeout");
}
}
}
}
} }
} }
@ -10361,8 +10376,8 @@ void MessagesManager::set_dialog_last_read_inbox_message_id(Dialog *d, MessageId
d->local_unread_count = local_unread_count; d->local_unread_count = local_unread_count;
if (need_unread_counter(d->order)) { if (need_unread_counter(d->order)) {
const int32 new_unread_count = d->server_unread_count + d->local_unread_count;
for (auto &list : get_dialog_lists(d)) { for (auto &list : get_dialog_lists(d)) {
int32 new_unread_count = d->server_unread_count + d->local_unread_count;
int32 delta = new_unread_count - old_unread_count; int32 delta = new_unread_count - old_unread_count;
if (delta != 0 && list.is_message_unread_count_inited_) { if (delta != 0 && list.is_message_unread_count_inited_) {
list.unread_message_total_count_ += delta; list.unread_message_total_count_ += delta;
@ -10388,6 +10403,12 @@ void MessagesManager::set_dialog_last_read_inbox_message_id(Dialog *d, MessageId
send_update_unread_chat_count(list.dialog_list_id, d->dialog_id, force_update, source); send_update_unread_chat_count(list.dialog_list_id, d->dialog_id, force_update, source);
} }
} }
bool was_unread = old_unread_count != 0 || d->is_marked_as_unread;
bool is_unread = new_unread_count != 0 || d->is_marked_as_unread;
if (!dialog_filters_.empty() && was_unread != is_unread) {
update_dialog_lists(d, get_dialog_orders(d), true, false, "set_dialog_last_read_inbox_message_id");
}
} }
if (message_id != MessageId::min() && d->last_read_inbox_message_id.is_valid() && if (message_id != MessageId::min() && d->last_read_inbox_message_id.is_valid() &&
@ -25092,6 +25113,10 @@ void MessagesManager::set_dialog_is_marked_as_unread(Dialog *d, bool is_marked_a
send_update_unread_chat_count(list.dialog_list_id, d->dialog_id, true, "set_dialog_is_marked_as_unread"); send_update_unread_chat_count(list.dialog_list_id, d->dialog_id, true, "set_dialog_is_marked_as_unread");
} }
} }
if (!dialog_filters_.empty()) {
update_dialog_lists(d, get_dialog_orders(d), true, false, "set_dialog_is_marked_as_unread");
}
} }
} }
@ -25387,6 +25412,18 @@ void MessagesManager::on_dialog_user_is_contact_updated(DialogId dialog_id, bool
repair_dialog_action_bar(d, "on_dialog_user_is_contact_updated"); repair_dialog_action_bar(d, "on_dialog_user_is_contact_updated");
} }
} }
if (!dialog_filters_.empty() && d->order != DEFAULT_ORDER) {
update_dialog_lists(d, get_dialog_orders(d), true, false, "on_dialog_user_is_contact_updated");
td_->contacts_manager_->for_each_secret_chat_with_user(
d->dialog_id.get_user_id(), [this](SecretChatId secret_chat_id) {
DialogId dialog_id(secret_chat_id);
auto d = get_dialog(dialog_id); // must not create the dialog
if (d != nullptr && d->is_update_new_chat_sent && d->order != DEFAULT_ORDER) {
update_dialog_lists(d, get_dialog_orders(d), true, false, "on_dialog_user_is_contact_updated");
}
});
}
} }
} }
@ -25426,6 +25463,18 @@ void MessagesManager::on_dialog_user_is_deleted_updated(DialogId dialog_id, bool
repair_dialog_action_bar(d, "on_dialog_user_is_deleted_updated"); repair_dialog_action_bar(d, "on_dialog_user_is_deleted_updated");
} }
} }
if (!dialog_filters_.empty() && d->order != DEFAULT_ORDER) {
update_dialog_lists(d, get_dialog_orders(d), true, false, "on_dialog_user_is_deleted_updated");
td_->contacts_manager_->for_each_secret_chat_with_user(
d->dialog_id.get_user_id(), [this](SecretChatId secret_chat_id) {
DialogId dialog_id(secret_chat_id);
auto d = get_dialog(dialog_id); // must not create the dialog
if (d != nullptr && d->is_update_new_chat_sent && d->order != DEFAULT_ORDER) {
update_dialog_lists(d, get_dialog_orders(d), true, false, "on_dialog_user_is_deleted_updated");
}
});
}
} }
} }