From 71fb1d87e0c84e9dc53f3d5448f458823153c953 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 19 Dec 2019 01:27:38 +0300 Subject: [PATCH] Copy secret chat action bars from corresponding private chats. GitOrigin-RevId: ced6ee8d98ba7798e8fe941b8506afbb0657d641 --- td/telegram/MessagesManager.cpp | 36 ++++++++++++++++++++++++++++++++- td/telegram/MessagesManager.h | 2 +- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 5fb8c637..1ea6cad7 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -6902,6 +6902,7 @@ void MessagesManager::change_dialog_report_spam_state_on_server(DialogId dialog_ } bool MessagesManager::can_report_dialog(DialogId dialog_id) const { + // doesn't include possibility of report from action bar switch (dialog_id.get_type()) { case DialogType::User: return td_->contacts_manager_->can_report_user(dialog_id.get_user_id()); @@ -6937,6 +6938,7 @@ void MessagesManager::report_dialog(DialogId dialog_id, const tl_object_ptrcan_report_spam; if (reason->get_id() == td_api::chatReportReasonSpam::ID && message_ids.empty()) { + // report from action bar if (dialog_id.get_type() == DialogType::SecretChat) { auto user_dialog_id = DialogId(td_->contacts_manager_->get_secret_chat_user_id(dialog_id.get_secret_chat_id())); user_d = get_dialog_force(user_dialog_id); @@ -15067,7 +15069,20 @@ td_api::object_ptr MessagesManager::get_chat_list_object(Folde return td_api::make_object(); } -td_api::object_ptr MessagesManager::get_chat_action_bar_object(const Dialog *d) { +td_api::object_ptr MessagesManager::get_chat_action_bar_object(const Dialog *d) const { + CHECK(d != nullptr); + if (d->dialog_id.get_type() == DialogType::SecretChat) { + auto user_id = td_->contacts_manager_->get_secret_chat_user_id(d->dialog_id.get_secret_chat_id()); + if (!user_id.is_valid()) { + return nullptr; + } + const Dialog *user_d = get_dialog(DialogId(user_id)); + if (user_d == nullptr) { + return nullptr; + } + return get_chat_action_bar_object(user_d); + } + if (!d->know_action_bar) { if (d->know_can_report_spam && d->dialog_id.get_type() != DialogType::SecretChat && d->can_report_spam) { return td_api::make_object(); @@ -22351,9 +22366,19 @@ void MessagesManager::send_update_new_chat(Dialog *d) { CHECK(d != nullptr); CHECK(d->messages == nullptr); auto chat_object = get_chat_object(d); + bool has_action_bar = chat_object->action_bar_ != nullptr; d->last_sent_has_scheduled_messages = chat_object->has_scheduled_messages_; send_closure(G()->td(), &Td::send_update, make_tl_object(std::move(chat_object))); d->is_update_new_chat_sent = true; + + if (has_action_bar && d->dialog_id.get_type() == DialogType::User) { + td_->contacts_manager_->for_each_secret_chat_with_user( + d->dialog_id.get_user_id(), [this, d](SecretChatId secret_chat_id) { + send_closure(G()->td(), &Td::send_update, + td_api::make_object(DialogId(secret_chat_id).get(), + get_chat_action_bar_object(d))); + }); + } } void MessagesManager::send_update_chat_draft_message(const Dialog *d) { @@ -22551,6 +22576,15 @@ void MessagesManager::send_update_chat_action_bar(const Dialog *d) { on_dialog_updated(d->dialog_id, "send_update_chat_action_bar"); send_closure(G()->td(), &Td::send_update, td_api::make_object(d->dialog_id.get(), get_chat_action_bar_object(d))); + + if (d->dialog_id.get_type() == DialogType::User) { + td_->contacts_manager_->for_each_secret_chat_with_user( + d->dialog_id.get_user_id(), [this, d](SecretChatId secret_chat_id) { + send_closure(G()->td(), &Td::send_update, + td_api::make_object(DialogId(secret_chat_id).get(), + get_chat_action_bar_object(d))); + }); + } } void MessagesManager::send_update_chat_has_scheduled_messages(Dialog *d) { diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 056f75ce..ff184933 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -2054,7 +2054,7 @@ class MessagesManager : public Actor { static td_api::object_ptr get_chat_list_object(FolderId folder_id); - static td_api::object_ptr get_chat_action_bar_object(const Dialog *d); + td_api::object_ptr get_chat_action_bar_object(const Dialog *d) const; td_api::object_ptr get_chat_object(const Dialog *d) const;