Skip to content

Commit

Permalink
Simplify DeletePhoneCallHistoryQuery.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Nov 11, 2021
1 parent e9695d2 commit f78f340
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 35 deletions.
6 changes: 6 additions & 0 deletions td/telegram/AffectedHistory.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ struct AffectedHistory {
, pts_count_(affected_history->pts_count_)
, is_final_(affected_history->offset_ <= 0) {
}

explicit AffectedHistory(tl_object_ptr<telegram_api::messages_affectedFoundMessages> &&affected_history)
: pts_(affected_history->pts_)
, pts_count_(affected_history->pts_count_)
, is_final_(affected_history->offset_ <= 0) {
}
};

} // namespace td
51 changes: 16 additions & 35 deletions td/telegram/MessagesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2757,53 +2757,33 @@ class DeleteMessagesByDateQuery final : public Td::ResultHandler {
};

class DeletePhoneCallHistoryQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
bool revoke_;
Promise<AffectedHistory> promise_;

void send_request() {
public:
explicit DeletePhoneCallHistoryQuery(Promise<AffectedHistory> &&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<Unit> &&promise) : promise_(std::move(promise)) {
}

void send(bool revoke) {
revoke_ = revoke;

send_request();
}

void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_deletePhoneCallHistory>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}

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<Unit>() : std::move(promise_);
auto pts = affected_messages->pts_;
auto pts_count = affected_messages->pts_count_;
auto update =
make_tl_object<telegram_api::updateDeleteMessages>(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<telegram_api::updateDeleteMessages>(std::move(affected_messages->messages_), 0, 0));
}
promise_.set_value(AffectedHistory(std::move(affected_messages)));
}

void on_error(Status status) final {
Expand Down Expand Up @@ -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<DeletePhoneCallHistoryQuery>(std::move(promise))->send(revoke);
AffectedHistoryQuery query = [td = td_, revoke](DialogId /*dialog_id*/, Promise<AffectedHistory> &&query_promise) {
td->create_handler<DeletePhoneCallHistoryQuery>(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<MessageId> &message_ids,
Expand Down

0 comments on commit f78f340

Please sign in to comment.