From 4b3c36e9242fed6c4be236c4c668cf382052c8ba Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 4 Dec 2019 21:44:40 +0300 Subject: [PATCH] Send updateChatHasScheduledMessages whenever a scheduled message is added or deleted. GitOrigin-RevId: df1f6b90fa611f89c6b0c95131c33a6cd446807b --- td/telegram/MessagesManager.cpp | 34 +++++++++++++++++++++++++-------- td/telegram/MessagesManager.h | 3 ++- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 814a0b79..65b567d6 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -5815,7 +5815,10 @@ void MessagesManager::on_update_delete_scheduled_messages(DialogId dialog_id, deleted_message_ids.push_back(message->message_id.get()); } } + send_update_delete_messages(dialog_id, std::move(deleted_message_ids), true, false); + + send_update_chat_has_scheduled_messages(d); } void MessagesManager::on_update_include_sponsored_dialog_to_unread_count() { @@ -8417,6 +8420,8 @@ void MessagesManager::delete_messages(DialogId dialog_id, const vectormessages == nullptr); - send_closure(G()->td(), &Td::send_update, make_tl_object(get_chat_object(d))); + auto chat_object = get_chat_object(d); + 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; } @@ -22080,11 +22091,16 @@ void MessagesManager::send_update_chat_action_bar(const Dialog *d) { td_api::make_object(d->dialog_id.get(), get_chat_action_bar_object(d))); } -void MessagesManager::send_update_chat_has_scheduled_messages(const Dialog *d) const { +void MessagesManager::send_update_chat_has_scheduled_messages(Dialog *d) { + bool has_scheduled_messages = d->has_scheduled_server_messages || d->scheduled_messages != nullptr; + if (has_scheduled_messages == d->last_sent_has_scheduled_messages) { + return; + } + d->last_sent_has_scheduled_messages = has_scheduled_messages; + LOG_CHECK(d->is_update_new_chat_sent) << "Wrong " << d->dialog_id << " in send_update_chat_has_scheduled_messages"; send_closure(G()->td(), &Td::send_update, - td_api::make_object( - d->dialog_id.get(), d->has_scheduled_server_messages || d->scheduled_messages != nullptr)); + td_api::make_object(d->dialog_id.get(), has_scheduled_messages)); } void MessagesManager::on_send_message_get_quick_ack(int64 random_id) { @@ -22932,9 +22948,8 @@ void MessagesManager::set_dialog_has_scheduled_server_messages(Dialog *d, bool h on_dialog_updated(d->dialog_id, "set_dialog_has_scheduled_server_messages"); LOG(INFO) << "Set " << d->dialog_id << " has_scheduled_server_messages to " << has_scheduled_server_messages; - if (d->scheduled_messages == nullptr) { - send_update_chat_has_scheduled_messages(d); - } + + send_update_chat_has_scheduled_messages(d); } void MessagesManager::on_update_dialog_folder_id(DialogId dialog_id, FolderId folder_id) { @@ -28430,7 +28445,8 @@ MessagesManager::Message *MessagesManager::continue_send_message(DialogId dialog auto result_message = add_message_to_dialog(d, std::move(m), true, &need_update, &need_update_dialog_pos, "resend message"); CHECK(result_message != nullptr); - // CHECK(need_update_dialog_pos == true); + + send_update_chat_has_scheduled_messages(d); send_update_new_message(d, result_message); if (need_update_dialog_pos) { @@ -28645,6 +28661,8 @@ void MessagesManager::on_binlog_events(vector &&events) { &need_update_dialog_pos, "forward message again")); send_update_new_message(to_dialog, forwarded_messages.back()); } + send_update_chat_has_scheduled_messages(to_dialog); + if (need_update_dialog_pos) { send_update_chat_last_message(to_dialog, "on_reforward_message"); } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 45410d72..a2cef2be 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1089,6 +1089,7 @@ class MessagesManager : public Actor { bool is_folder_id_inited = false; bool need_repair_server_unread_count = false; bool is_marked_as_unread = false; + bool last_sent_has_scheduled_messages = false; bool has_scheduled_server_messages = false; bool has_loaded_scheduled_messages_from_database = false; @@ -1869,7 +1870,7 @@ class MessagesManager : public Actor { void send_update_chat_action_bar(const Dialog *d); - void send_update_chat_has_scheduled_messages(const Dialog *d) const; + void send_update_chat_has_scheduled_messages(Dialog *d); void hide_dialog_action_bar(Dialog *d);