From 2f1de10541077f996f181e22ec659fc2bf4f6a08 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 31 Jan 2024 02:47:43 +0300 Subject: [PATCH] Add and use MessagesManager::clear_dialog_draft_by_sent_message. --- td/telegram/MessagesManager.cpp | 31 ++++++++++++++----------------- td/telegram/MessagesManager.h | 2 ++ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index ee3023d8b..5fb0c0d97 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -24011,13 +24011,7 @@ Result> MessagesManager::send_message( return get_message_object(dialog_id, m, "send_message"); } - if (m->clear_draft) { - if (top_thread_message_id.is_valid()) { - set_dialog_draft_message(dialog_id, top_thread_message_id, nullptr).ignore(); - } else { - update_dialog_draft_message(d, nullptr, false, !need_update_dialog_pos); - } - } + clear_dialog_draft_by_sent_message(d, m, !need_update_dialog_pos); save_send_message_log_event(dialog_id, m); do_send_message(dialog_id, m); @@ -25177,13 +25171,7 @@ Result> MessagesManager::send_inline_query_r return get_message_object(dialog_id, m, "send_inline_query_result_message"); } - if (m->clear_draft) { - if (top_thread_message_id.is_valid()) { - set_dialog_draft_message(dialog_id, top_thread_message_id, nullptr).ignore(); - } else { - update_dialog_draft_message(d, nullptr, false, !need_update_dialog_pos); - } - } + clear_dialog_draft_by_sent_message(d, m, !need_update_dialog_pos); send_update_new_message(d, m); if (need_update_dialog_pos) { @@ -27546,9 +27534,7 @@ Result MessagesManager::add_local_message( } } - if (result->clear_draft) { - update_dialog_draft_message(d, nullptr, false, !need_update_dialog_pos); - } + clear_dialog_draft_by_sent_message(d, result, !need_update_dialog_pos); send_update_new_message(d, result); if (need_update_dialog_pos) { @@ -30193,6 +30179,17 @@ bool MessagesManager::update_dialog_draft_message(Dialog *d, unique_ptrclear_draft || td_->auth_manager_->is_bot()) { + return; + } + if (m->initial_top_thread_message_id.is_valid()) { + set_dialog_draft_message(d->dialog_id, m->initial_top_thread_message_id, nullptr).ignore(); + } else { + update_dialog_draft_message(d, nullptr, false, need_update_dialog_pos); + } +} + void MessagesManager::on_update_dialog_is_pinned(FolderId folder_id, DialogId dialog_id, bool is_pinned) { if (td_->auth_manager_->is_bot()) { // just in case diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 5e7d9aa4d..2726b05e9 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -2849,6 +2849,8 @@ class MessagesManager final : public Actor { bool update_dialog_draft_message(Dialog *d, unique_ptr &&draft_message, bool from_update, bool need_update_dialog_pos); + void clear_dialog_draft_by_sent_message(Dialog *d, const Message *m, bool need_update_dialog_pos); + void save_dialog_draft_message_on_server(DialogId dialog_id); void on_saved_dialog_draft_message(DialogId dialog_id, uint64 generation);