From 23ad80e3a96752ee9f6b008ee66d7cf40dd8f063 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 29 Apr 2020 22:28:57 +0300 Subject: [PATCH] Silence warning about changed dialog order if dialog info was received from serverr. GitOrigin-RevId: b6211153533746180307542d3e19fcd10aac63d2 --- td/telegram/ContactsManager.cpp | 24 ++++++++++++++++++++++++ td/telegram/ContactsManager.h | 11 +++++++++++ td/telegram/MessagesManager.cpp | 3 ++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 38355ec24..fa3fc6297 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -7043,6 +7043,7 @@ void ContactsManager::on_get_user(tl_object_ptr &&user_ptr, u->cache_version = User::CACHE_VERSION; u->need_save_to_database = true; } + u->is_received_from_server = true; update_user(u, user_id); } @@ -11516,6 +11517,25 @@ ContactsManager::User *ContactsManager::get_user(UserId user_id) { } } +bool ContactsManager::is_dialog_info_received_from_server(DialogId dialog_id) const { + switch (dialog_id.get_type()) { + case DialogType::User: { + auto u = get_user(dialog_id.get_user_id()); + return u != nullptr && u->is_received_from_server; + } + case DialogType::Chat: { + auto c = get_chat(dialog_id.get_chat_id()); + return c != nullptr && c->is_received_from_server; + } + case DialogType::Channel: { + auto c = get_channel(dialog_id.get_channel_id()); + return c != nullptr && c->is_received_from_server; + } + default: + return false; + } +} + void ContactsManager::reload_dialog_info(DialogId dialog_id, Promise &&promise) { switch (dialog_id.get_type()) { case DialogType::User: @@ -12879,6 +12899,7 @@ void ContactsManager::on_chat_update(telegram_api::chat &chat, const char *sourc c->cache_version = Chat::CACHE_VERSION; c->need_save_to_database = true; } + c->is_received_from_server = true; update_chat(c, chat_id); } @@ -12909,6 +12930,7 @@ void ContactsManager::on_chat_update(telegram_api::chatForbidden &chat, const ch c->cache_version = Chat::CACHE_VERSION; c->need_save_to_database = true; } + c->is_received_from_server = true; update_chat(c, chat_id); } @@ -13055,6 +13077,7 @@ void ContactsManager::on_chat_update(telegram_api::channel &channel, const char c->cache_version = Channel::CACHE_VERSION; c->need_save_to_database = true; } + c->is_received_from_server = true; update_channel(c, channel_id); } @@ -13140,6 +13163,7 @@ void ContactsManager::on_chat_update(telegram_api::channelForbidden &channel, co c->cache_version = Channel::CACHE_VERSION; c->need_save_to_database = true; } + c->is_received_from_server = true; update_channel(c, channel_id); } diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index ffe34550b..60c168add 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -422,6 +422,8 @@ class ContactsManager : public Actor { bool have_min_user(UserId user_id) const; bool have_user_force(UserId user_id); + bool is_dialog_info_received_from_server(DialogId dialog_id) const; + void reload_dialog_info(DialogId dialog_id, Promise &&promise); static void send_get_me_query(Td *td, Promise &&promise); @@ -608,6 +610,8 @@ class ContactsManager : public Actor { bool is_being_saved = false; // is current user being saved to the database bool is_status_saved = false; // is current user status being saved/is saved to the database + bool is_received_from_server = false; // true, if the user was received from the server and not the database + uint64 logevent_id = 0; template @@ -696,6 +700,9 @@ class ContactsManager : public Actor { bool is_saved = false; // is current chat version being saved/is saved to the database bool is_being_saved = false; // is current chat being saved to the database + + bool is_received_from_server = false; // true, if the chat was received from the server and not the database + uint64 logevent_id = 0; template @@ -765,6 +772,9 @@ class ContactsManager : public Actor { bool is_saved = false; // is current channel version being saved/is saved to the database bool is_being_saved = false; // is current channel being saved to the database + + bool is_received_from_server = false; // true, if the channel was received from the server and not the database + uint64 logevent_id = 0; template @@ -839,6 +849,7 @@ class ContactsManager : public Actor { bool is_saved = false; // is current secret chat version being saved/is saved to the database bool is_being_saved = false; // is current secret chat being saved to the database + uint64 logevent_id = 0; template diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 866f59beb..707448daf 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -28182,7 +28182,8 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr &&last_datab } update_dialog_pos(d, "fix_new_dialog 7", true, is_loaded_from_database); - if (is_loaded_from_database && d->order != order && order < get_dialog_order({}, MIN_PINNED_DIALOG_DATE - 1)) { + if (is_loaded_from_database && d->order != order && order < get_dialog_order({}, MIN_PINNED_DIALOG_DATE - 1) && + !td_->contacts_manager_->is_dialog_info_received_from_server(dialog_id)) { LOG(ERROR) << dialog_id << " has order " << d->order << " instead of saved to database order " << order; }