diff --git a/CMakeLists.txt b/CMakeLists.txt index 66e4cc593..64f4debca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -452,6 +452,7 @@ set(TDLIB_SOURCE td/mtproto/utils.h td/telegram/AccessRights.h + td/telegram/AffectedHistory.h td/telegram/AnimationsManager.h td/telegram/AudiosManager.h td/telegram/AuthManager.h diff --git a/td/telegram/AffectedHistory.h b/td/telegram/AffectedHistory.h new file mode 100644 index 000000000..4c36cf259 --- /dev/null +++ b/td/telegram/AffectedHistory.h @@ -0,0 +1,27 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#pragma once + +#include "td/telegram/telegram_api.h" + +#include "td/utils/common.h" + +namespace td { + +struct AffectedHistory { + int32 pts_; + int32 pts_count_; + bool is_final_; + + 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 8ec6f86aa..eaef96d4a 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -635,7 +635,7 @@ class UnpinAllMessagesQuery final : public Td::ResultHandler { return on_error(result_ptr.move_as_error()); } - promise_.set_value(result_ptr.move_as_ok()); + promise_.set_value(AffectedHistory(result_ptr.move_as_ok())); } void on_error(Status status) final { @@ -2663,7 +2663,7 @@ class DeleteHistoryQuery final : public Td::ResultHandler { return on_error(result_ptr.move_as_error()); } - promise_.set_value(result_ptr.move_as_ok()); + promise_.set_value(AffectedHistory(result_ptr.move_as_ok())); } void on_error(Status status) final { @@ -2747,7 +2747,7 @@ class DeleteMessagesByDateQuery final : public Td::ResultHandler { return on_error(result_ptr.move_as_error()); } - promise_.set_value(result_ptr.move_as_ok()); + promise_.set_value(AffectedHistory(result_ptr.move_as_ok())); } void on_error(Status status) final { @@ -2879,7 +2879,7 @@ class DeleteUserHistoryQuery final : public Td::ResultHandler { return on_error(result_ptr.move_as_error()); } - promise_.set_value(result_ptr.move_as_ok()); + promise_.set_value(AffectedHistory(result_ptr.move_as_ok())); } void on_error(Status status) final { @@ -2913,7 +2913,7 @@ class ReadMentionsQuery final : public Td::ResultHandler { return on_error(result_ptr.move_as_error()); } - promise_.set_value(result_ptr.move_as_ok()); + promise_.set_value(AffectedHistory(result_ptr.move_as_ok())); } void on_error(Status status) final { @@ -22463,25 +22463,25 @@ void MessagesManager::on_get_affected_history(DialogId dialog_id, AffectedHistor Promise &&promise) { TRY_STATUS_PROMISE(promise, G()->close_status()); - if (affected_history->pts_count_ > 0) { + if (affected_history.pts_count_ > 0) { if (get_affected_messages) { - affected_history->pts_count_ = 0; + affected_history.pts_count_ = 0; } - auto update_promise = affected_history->offset_ > 0 ? Promise() : std::move(promise); + auto update_promise = affected_history.is_final_ ? std::move(promise) : Promise(); if (dialog_id.get_type() == DialogType::Channel) { td_->messages_manager_->add_pending_channel_update(dialog_id, make_tl_object(), - affected_history->pts_, affected_history->pts_count_, + affected_history.pts_, affected_history.pts_count_, std::move(update_promise), "on_get_affected_history"); } else { - td_->updates_manager_->add_pending_pts_update(make_tl_object(), affected_history->pts_, - affected_history->pts_count_, Time::now(), - std::move(update_promise), "on_get_affected_history"); + td_->updates_manager_->add_pending_pts_update(make_tl_object(), affected_history.pts_, + affected_history.pts_count_, Time::now(), std::move(update_promise), + "on_get_affected_history"); } - } else if (affected_history->offset_ <= 0) { + } else if (affected_history.is_final_) { promise.set_value(Unit()); } - if (affected_history->offset_ > 0) { + if (!affected_history.is_final_) { run_affected_history_query_until_complete(dialog_id, std::move(query), get_affected_messages, std::move(promise)); } } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 3118e33df..521506743 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -7,6 +7,7 @@ #pragma once #include "td/telegram/AccessRights.h" +#include "td/telegram/AffectedHistory.h" #include "td/telegram/ChannelId.h" #include "td/telegram/DialogAction.h" #include "td/telegram/DialogDate.h" @@ -92,8 +93,6 @@ class MessageContent; class MultiSequenceDispatcher; class Td; -using AffectedHistory = tl_object_ptr; - class MessagesManager final : public Actor { public: // static constexpr int32 MESSAGE_FLAG_IS_UNREAD = 1 << 0;