From de0e0d81737641ce23417763a58c7bceb3abcf5a Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 21 Oct 2019 23:47:58 +0300 Subject: [PATCH] Unify *Full.is_changed usage. GitOrigin-RevId: 222ac98bc06fa5652add8e5d43c7861906209136 --- td/telegram/ContactsManager.cpp | 45 ++++++++++++++++++++------------- td/telegram/ContactsManager.h | 15 ++++++----- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 1612df96..73265d82 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -7841,23 +7841,31 @@ void ContactsManager::update_user_full(UserFull *user_full, UserId user_id, bool user_full->is_is_blocked_changed = false; } - if (user_full->is_changed || user_full->need_send_update) { + user_full->need_send_update |= user_full->is_changed; + user_full->need_save_to_database |= user_full->is_changed; + user_full->is_changed = false; + if (user_full->need_send_update) { send_closure(G()->td(), &Td::send_update, make_tl_object(get_user_id_object(user_id, "updateUserFullInfo"), get_user_full_info_object(user_id, user_full))); - - if (!from_database && user_full->is_changed) { - save_user_full(user_full, user_id); - } - user_full->is_changed = false; user_full->need_send_update = false; } + if (!from_database && user_full->need_save_to_database) { + send_closure(G()->td(), &Td::send_update, + make_tl_object(get_user_id_object(user_id, "updateUserFullInfo"), + get_user_full_info_object(user_id, user_full))); + user_full->need_save_to_database = false; + } } void ContactsManager::update_chat_full(ChatFull *chat_full, ChatId chat_id, bool from_database) { CHECK(chat_full != nullptr); unavailable_chat_fulls_.erase(chat_id); // don't needed anymore - if (chat_full->is_changed || chat_full->need_send_update) { + + chat_full->need_send_update |= chat_full->is_changed; + chat_full->need_save_to_database |= chat_full->is_changed; + chat_full->is_changed = false; + if (chat_full->need_send_update) { vector administrator_user_ids; vector bot_user_ids; for (const auto &participant : chat_full->participants) { @@ -7876,32 +7884,35 @@ void ContactsManager::update_chat_full(ChatFull *chat_full, ChatId chat_id, bool G()->td(), &Td::send_update, make_tl_object(get_basic_group_id_object(chat_id, "update_chat_full"), get_basic_group_full_info_object(chat_full))); - - if (!from_database && chat_full->is_changed) { - save_chat_full(chat_full, chat_id); - } - chat_full->is_changed = false; chat_full->need_send_update = false; } + if (!from_database && chat_full->need_save_to_database) { + save_chat_full(chat_full, chat_id); + chat_full->need_save_to_database = false; + } } void ContactsManager::update_channel_full(ChannelFull *channel_full, ChannelId channel_id, bool from_database) { CHECK(channel_full != nullptr); unavailable_channel_fulls_.erase(channel_id); // don't needed anymore + if (channel_full->participant_count < channel_full->administrator_count) { + channel_full->administrator_count = channel_full->participant_count; + } + + channel_full->need_send_update |= channel_full->is_changed; channel_full->need_save_to_database |= channel_full->is_changed; - if (channel_full->is_changed) { + channel_full->is_changed = false; + if (channel_full->need_send_update) { if (channel_full->linked_channel_id.is_valid()) { td_->messages_manager_->force_create_dialog(DialogId(channel_full->linked_channel_id), "update_channel_full"); } - if (channel_full->participant_count < channel_full->administrator_count) { - channel_full->administrator_count = channel_full->participant_count; - } - channel_full->is_changed = false; + send_closure( G()->td(), &Td::send_update, make_tl_object(get_supergroup_id_object(channel_id, "update_channel_full"), get_supergroup_full_info_object(channel_full))); + channel_full->need_send_update = false; } if (!from_database && channel_full->need_save_to_database) { channel_full->need_save_to_database = false; diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 8c56c3a6..77b5bc76 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -600,8 +600,9 @@ class ContactsManager : public Actor { bool is_is_blocked_changed = true; bool is_common_chat_count_changed = true; - bool is_changed = true; // have new changes that needs to be sent to the client and database - bool need_send_update = true; // have new changes that needs to be sent only to the client + bool is_changed = true; // have new changes that need to be sent to the client and database + bool need_send_update = true; // have new changes that need only to be sent to the client + bool need_save_to_database = true; // have new changes that need onto be saved to the database double expires_at = 0.0; @@ -664,8 +665,9 @@ class ContactsManager : public Actor { bool can_set_username = false; - bool is_changed = true; // have new changes that needs to be sent to the client and database - bool need_send_update = true; // have new changes that needs to be sent only to the client + bool is_changed = true; // have new changes that need to be sent to the client and database + bool need_send_update = true; // have new changes that need only to be sent to the client + bool need_save_to_database = true; // have new changes that need onto be saved to the database template void store(StorerT &storer) const; @@ -746,8 +748,9 @@ class ContactsManager : public Actor { bool can_view_statistics = false; bool is_all_history_available = true; - bool is_changed = true; // have new changes that needs to be sent to the client and database - bool need_save_to_database = true; // have new changes that needs only to be saved to database + bool is_changed = true; // have new changes that need to be sent to the client and database + bool need_send_update = true; // have new changes that need only to be sent to the client + bool need_save_to_database = true; // have new changes that need onto be saved to the database double expires_at = 0.0; bool is_expired() const;