Simplify MessagesManager::set_dialog_order.

GitOrigin-RevId: a91e590024087f71146637064b5a44a4a2da9960
This commit is contained in:
levlam 2020-03-18 23:19:23 +03:00
parent fd10b27847
commit 443924ca11
2 changed files with 9 additions and 24 deletions

View File

@ -28267,23 +28267,9 @@ bool MessagesManager::set_dialog_order(Dialog *d, int64 new_order, bool need_sen
DialogDate new_date(new_order, dialog_id);
auto &list = get_dialog_list(d->folder_id);
std::set<DialogDate> *ordered_dialogs_set = nullptr;
switch (dialog_id.get_type()) {
case DialogType::User:
case DialogType::Chat:
case DialogType::Channel:
case DialogType::SecretChat:
ordered_dialogs_set = &list.ordered_server_dialogs_;
break;
case DialogType::None:
default:
UNREACHABLE();
return false;
}
if (old_date == new_date) {
if (new_order == DEFAULT_ORDER && ordered_dialogs_set->count(old_date) == 0) {
ordered_dialogs_set->insert(new_date);
if (new_order == DEFAULT_ORDER) {
list.ordered_server_dialogs_.insert(new_date);
}
LOG(INFO) << "Dialog order is not changed: " << new_order << " from " << source;
return false;
@ -28297,7 +28283,7 @@ bool MessagesManager::set_dialog_order(Dialog *d, int64 new_order, bool need_sen
}
need_update = true;
}
if (ordered_dialogs_set->erase(old_date) == 0) {
if (list.ordered_server_dialogs_.erase(old_date) == 0) {
LOG_IF(ERROR, d->order != DEFAULT_ORDER) << dialog_id << " not found in the chat list from " << source;
}
LOG_IF(ERROR, is_loaded_from_database && d->order != DEFAULT_ORDER)
@ -28309,7 +28295,7 @@ bool MessagesManager::set_dialog_order(Dialog *d, int64 new_order, bool need_sen
need_update = true;
updated_to = new_order;
}
ordered_dialogs_set->insert(new_date);
list.ordered_server_dialogs_.insert(new_date);
bool add_to_hints = (d->order == DEFAULT_ORDER);
bool was_sponsored = (d->order == SPONSORED_DIALOG_ORDER);
@ -28424,7 +28410,7 @@ bool MessagesManager::set_dialog_order(Dialog *d, int64 new_order, bool need_sen
void MessagesManager::update_last_dialog_date(FolderId folder_id) {
auto &list = get_dialog_list(folder_id);
auto old_last_dialog_date = list.last_dialog_date_;
list.last_dialog_date_ = list.last_server_dialog_date_; // std::min
list.last_dialog_date_ = list.last_server_dialog_date_;
CHECK(old_last_dialog_date <= list.last_dialog_date_);
LOG(INFO) << "Update last dialog date in " << folder_id << " from " << old_last_dialog_date << " to "

View File

@ -1226,12 +1226,11 @@ class MessagesManager : public Actor {
int32 server_dialog_total_count_ = -1;
int32 secret_chat_total_count_ = -1;
std::set<DialogDate> ordered_dialogs_; // all dialogs with date <= last_dialog_date_
std::set<DialogDate> ordered_server_dialogs_; // all known dialogs, including with default order
// date of last dialog in the dialog list
// last_dialog_date_ == min(last_server_dialog_date_, last_secret_chat_dialog_date_)
// date of the last dialog in loaded the dialog list prefix
DialogDate last_dialog_date_ = MIN_DIALOG_DATE; // in memory
std::set<DialogDate> ordered_dialogs_; // all dialogs with date <= last_dialog_date_
std::set<DialogDate> ordered_server_dialogs_; // all known dialogs, including with default order
// date of last known user/group/channel dialog in the right order
DialogDate last_server_dialog_date_ = MIN_DIALOG_DATE;