From f78f3407f8e503d2a4695d3235d5c3f7a08bdf09 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 11 Nov 2021 21:34:27 +0300 Subject: [PATCH] Simplify DeletePhoneCallHistoryQuery. --- td/telegram/AffectedHistory.h | 6 ++++ td/telegram/MessagesManager.cpp | 51 +++++++++++---------------------- 2 files changed, 22 insertions(+), 35 deletions(-) diff --git a/td/telegram/AffectedHistory.h b/td/telegram/AffectedHistory.h index 4c36cf259..fd601e550 100644 --- a/td/telegram/AffectedHistory.h +++ b/td/telegram/AffectedHistory.h @@ -22,6 +22,12 @@ struct AffectedHistory { , pts_count_(affected_history->pts_count_) , is_final_(affected_history->offset_ <= 0) { } + + explicit AffectedHistory(tl_object_ptr &&affected_history) + : pts_(affected_history->pts_) + , pts_count_(affected_history->pts_count_) + , is_final_(affected_history->offset_ <= 0) { + } }; } // namespace td diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index eaef96d4a..d535f639c 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -2757,28 +2757,21 @@ class DeleteMessagesByDateQuery final : public Td::ResultHandler { }; class DeletePhoneCallHistoryQuery final : public Td::ResultHandler { - Promise promise_; - bool revoke_; + Promise promise_; - void send_request() { + public: + explicit DeletePhoneCallHistoryQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(bool revoke) { int32 flags = 0; - if (revoke_) { + if (revoke) { flags |= telegram_api::messages_deletePhoneCallHistory::REVOKE_MASK; } send_query( G()->net_query_creator().create(telegram_api::messages_deletePhoneCallHistory(flags, false /*ignored*/))); } - public: - explicit DeletePhoneCallHistoryQuery(Promise &&promise) : promise_(std::move(promise)) { - } - - void send(bool revoke) { - revoke_ = revoke; - - send_request(); - } - void on_result(BufferSlice packet) final { auto result_ptr = fetch_result(packet); if (result_ptr.is_error()) { @@ -2786,24 +2779,11 @@ class DeletePhoneCallHistoryQuery final : public Td::ResultHandler { } auto affected_messages = result_ptr.move_as_ok(); - CHECK(affected_messages->get_id() == telegram_api::messages_affectedFoundMessages::ID); - - if (affected_messages->pts_count_ > 0) { - auto promise = affected_messages->offset_ > 0 ? Promise() : std::move(promise_); - auto pts = affected_messages->pts_; - auto pts_count = affected_messages->pts_count_; - auto update = - make_tl_object(std::move(affected_messages->messages_), pts, pts_count); - td_->updates_manager_->add_pending_pts_update(std::move(update), pts, pts_count, Time::now(), std::move(promise), - "delete phone call history query"); - } else if (affected_messages->offset_ <= 0) { - promise_.set_value(Unit()); - } - - if (affected_messages->offset_ > 0) { - send_request(); - return; + if (!affected_messages->messages_.empty()) { + td_->messages_manager_->process_pts_update( + make_tl_object(std::move(affected_messages->messages_), 0, 0)); } + promise_.set_value(AffectedHistory(std::move(affected_messages))); } void on_error(Status status) final { @@ -10733,10 +10713,11 @@ void MessagesManager::delete_all_call_messages_on_server(bool revoke, uint64 log log_event_id = save_delete_all_call_messages_on_server_log_event(revoke); } - auto new_promise = get_erase_log_event_promise(log_event_id, std::move(promise)); - promise = std::move(new_promise); // to prevent self-move - - td_->create_handler(std::move(promise))->send(revoke); + AffectedHistoryQuery query = [td = td_, revoke](DialogId /*dialog_id*/, Promise &&query_promise) { + td->create_handler(std::move(query_promise))->send(revoke); + }; + run_affected_history_query_until_complete(DialogId(), std::move(query), false, + get_erase_log_event_promise(log_event_id, std::move(promise))); } void MessagesManager::find_messages(const Message *m, vector &message_ids,