From 9d229b7ad11c032b85dd178d96a99fc9ba8b52f9 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 11 Oct 2019 02:59:40 +0300 Subject: [PATCH] Update action bar when user is added to contacts. GitOrigin-RevId: 52883ca7e29a3f1b9fe86a7cb210daba5c8cef46 --- td/telegram/ContactsManager.cpp | 5 +++-- td/telegram/MessagesManager.cpp | 27 +++++++++++++++++++++++++-- td/telegram/MessagesManager.h | 4 +++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 8f6693aed..a030d41a4 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -6948,6 +6948,7 @@ void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, boo update_contacts_hints(u, user_id, from_database); } if (u->is_is_contact_changed) { + td_->messages_manager_->on_dialog_user_is_contact_updated(DialogId(user_id), u->is_contact); if (u->is_contact) { auto user_full = get_user_full(user_id); if (user_full != nullptr && user_full->need_phone_number_privacy_exception) { @@ -7249,7 +7250,7 @@ void ContactsManager::update_user_full(UserFull *user_full, UserId user_id, bool user_full->is_common_chat_count_changed = false; } if (user_full->is_is_blocked_changed) { - td_->messages_manager_->on_dialog_is_blocked_updated(DialogId(user_id), user_full->is_blocked); + td_->messages_manager_->on_dialog_user_is_blocked_updated(DialogId(user_id), user_full->is_blocked); user_full->is_is_blocked_changed = false; } @@ -8034,7 +8035,7 @@ void ContactsManager::on_update_user_blocked(UserId user_id, bool is_blocked) { UserFull *user_full = get_user_full_force(user_id); if (user_full == nullptr || !user_full->is_inited) { - td_->messages_manager_->on_dialog_is_blocked_updated(DialogId(user_id), is_blocked); + td_->messages_manager_->on_dialog_user_is_blocked_updated(DialogId(user_id), is_blocked); } if (user_full == nullptr) { return; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 985e45d38..d0d9e10b6 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -22180,7 +22180,30 @@ void MessagesManager::on_dialog_permissions_updated(DialogId dialog_id) { } } -void MessagesManager::on_dialog_is_blocked_updated(DialogId dialog_id, bool is_blocked) { +void MessagesManager::on_dialog_user_is_contact_updated(DialogId dialog_id, bool is_contact) { + CHECK(dialog_id.get_type() == DialogType::User); + auto d = get_dialog(dialog_id); // called from update_user, must not create the dialog + if (d != nullptr && d->is_update_new_chat_sent) { + if (d->know_action_bar) { + if (is_contact) { + if (d->can_block_user || d->can_add_contact) { + d->can_block_user = false; + d->can_add_contact = false; + send_update_chat_action_bar(d); + } + } else { + d->know_action_bar = false; + if (have_input_peer(dialog_id, AccessRights::Read)) { + repair_dialog_action_bar(dialog_id); + } + // there is no need to change action bar + on_dialog_updated(dialog_id, "on_dialog_user_is_contact_updated"); + } + } + } +} + +void MessagesManager::on_dialog_user_is_blocked_updated(DialogId dialog_id, bool is_blocked) { CHECK(dialog_id.get_type() == DialogType::User); auto d = get_dialog(dialog_id); // called from update_user_full, must not create the dialog if (d != nullptr && d->is_update_new_chat_sent) { @@ -22199,7 +22222,7 @@ void MessagesManager::on_dialog_is_blocked_updated(DialogId dialog_id, bool is_b repair_dialog_action_bar(dialog_id); } // there is no need to change action bar - on_dialog_updated(dialog_id, "on_dialog_is_blocked_updated"); + on_dialog_updated(dialog_id, "on_dialog_user_is_blocked_updated"); } } } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 2f092f9ed..92e77be71 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -642,7 +642,9 @@ class MessagesManager : public Actor { void on_dialog_title_updated(DialogId dialog_id); void on_dialog_username_updated(DialogId dialog_id, const string &old_username, const string &new_username); void on_dialog_permissions_updated(DialogId dialog_id); - void on_dialog_is_blocked_updated(DialogId dialog_id, bool is_blocked); + + void on_dialog_user_is_contact_updated(DialogId dialog_id, bool is_contact); + void on_dialog_user_is_blocked_updated(DialogId dialog_id, bool is_blocked); void on_resolved_username(const string &username, DialogId dialog_id); void drop_username(const string &username);