Immediately unload messages in closed chats after updates.channelDifferenceTooLong.

This commit is contained in:
levlam 2023-07-24 15:42:38 +03:00
parent 53c7cfbf02
commit 62677720fc
2 changed files with 21 additions and 4 deletions

View File

@ -5992,7 +5992,7 @@ void MessagesManager::on_pending_unload_dialog_timeout_callback(void *messages_m
auto messages_manager = static_cast<MessagesManager *>(messages_manager_ptr); auto messages_manager = static_cast<MessagesManager *>(messages_manager_ptr);
send_closure_later(messages_manager->actor_id(messages_manager), &MessagesManager::unload_dialog, send_closure_later(messages_manager->actor_id(messages_manager), &MessagesManager::unload_dialog,
DialogId(dialog_id_int)); DialogId(dialog_id_int), -1);
} }
void MessagesManager::on_dialog_unmute_timeout_callback(void *messages_manager_ptr, int64 dialog_id_int) { void MessagesManager::on_dialog_unmute_timeout_callback(void *messages_manager_ptr, int64 dialog_id_int) {
@ -11853,10 +11853,13 @@ double MessagesManager::get_next_unload_dialog_delay(Dialog *d) const {
return delay + delay * 1e-9 * d->unload_dialog_delay_seed; return delay + delay * 1e-9 * d->unload_dialog_delay_seed;
} }
void MessagesManager::unload_dialog(DialogId dialog_id) { void MessagesManager::unload_dialog(DialogId dialog_id, int32 delay) {
if (G()->close_flag()) { if (G()->close_flag()) {
return; return;
} }
if (delay < 0) {
delay = get_unload_dialog_delay() - 2;
}
Dialog *d = get_dialog(dialog_id); Dialog *d = get_dialog(dialog_id);
CHECK(d != nullptr); CHECK(d != nullptr);
@ -11876,7 +11879,7 @@ void MessagesManager::unload_dialog(DialogId dialog_id) {
bool has_left_to_unload_messages = false; bool has_left_to_unload_messages = false;
auto to_unload_message_ids = auto to_unload_message_ids =
find_unloadable_messages(d, G()->unix_time_cached() - get_unload_dialog_delay() + 2, has_left_to_unload_messages); find_unloadable_messages(d, G()->unix_time_cached() - delay, has_left_to_unload_messages);
vector<int64> unloaded_message_ids; vector<int64> unloaded_message_ids;
vector<unique_ptr<Message>> unloaded_messages; vector<unique_ptr<Message>> unloaded_messages;
@ -20618,6 +20621,11 @@ void MessagesManager::close_dialog(Dialog *d) {
CHECK(!d->has_unload_timeout); CHECK(!d->has_unload_timeout);
pending_unload_dialog_timeout_.set_timeout_in(dialog_id.get(), get_next_unload_dialog_delay(d)); pending_unload_dialog_timeout_.set_timeout_in(dialog_id.get(), get_next_unload_dialog_delay(d));
d->has_unload_timeout = true; d->has_unload_timeout = true;
if (d->need_unload_on_close) {
unload_dialog(dialog_id, 0);
d->need_unload_on_close = false;
}
} }
dialog_viewed_messages_.erase(dialog_id); dialog_viewed_messages_.erase(dialog_id);
@ -38569,6 +38577,14 @@ void MessagesManager::on_get_channel_dialog(DialogId dialog_id, MessageId last_m
// offline. It is the best way for gaps support, but it is pretty hard to implement correctly. // offline. It is the best way for gaps support, but it is pretty hard to implement correctly.
// It should be also noted that some messages like outgoing live location messages shouldn't be deleted. // It should be also noted that some messages like outgoing live location messages shouldn't be deleted.
if (is_message_unload_enabled()) {
if (d->open_count == 0) {
unload_dialog(dialog_id, 0);
} else {
d->need_unload_on_close = true;
}
}
if (last_message_id > d->last_new_message_id && !td_->auth_manager_->is_bot()) { if (last_message_id > d->last_new_message_id && !td_->auth_manager_->is_bot()) {
// TODO properly support last_message_id <= d->last_new_message_id // TODO properly support last_message_id <= d->last_new_message_id
set_dialog_first_database_message_id(d, MessageId(), "on_get_channel_dialog 6"); set_dialog_first_database_message_id(d, MessageId(), "on_get_channel_dialog 6");

View File

@ -1403,6 +1403,7 @@ class MessagesManager final : public Actor {
bool has_outgoing_messages = false; bool has_outgoing_messages = false;
bool was_opened = false; bool was_opened = false;
bool need_unload_on_close = false;
bool need_restore_reply_markup = true; bool need_restore_reply_markup = true;
bool need_drop_default_send_message_as_dialog_id = false; bool need_drop_default_send_message_as_dialog_id = false;
@ -2035,7 +2036,7 @@ class MessagesManager final : public Actor {
double get_next_unload_dialog_delay(Dialog *d) const; double get_next_unload_dialog_delay(Dialog *d) const;
void unload_dialog(DialogId dialog_id); void unload_dialog(DialogId dialog_id, int32 delay);
void clear_dialog_message_list(Dialog *d, bool remove_from_dialog_list, int32 last_message_date); void clear_dialog_message_list(Dialog *d, bool remove_from_dialog_list, int32 last_message_date);