Add struct AffectedHistory.

This commit is contained in:
levlam 2021-11-11 21:13:03 +03:00
parent f22d96ac9c
commit e9695d2fcc
4 changed files with 43 additions and 16 deletions

View File

@ -452,6 +452,7 @@ set(TDLIB_SOURCE
td/mtproto/utils.h td/mtproto/utils.h
td/telegram/AccessRights.h td/telegram/AccessRights.h
td/telegram/AffectedHistory.h
td/telegram/AnimationsManager.h td/telegram/AnimationsManager.h
td/telegram/AudiosManager.h td/telegram/AudiosManager.h
td/telegram/AuthManager.h td/telegram/AuthManager.h

View File

@ -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<telegram_api::messages_affectedHistory> &&affected_history)
: pts_(affected_history->pts_)
, pts_count_(affected_history->pts_count_)
, is_final_(affected_history->offset_ <= 0) {
}
};
} // namespace td

View File

@ -635,7 +635,7 @@ class UnpinAllMessagesQuery final : public Td::ResultHandler {
return on_error(result_ptr.move_as_error()); 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 { void on_error(Status status) final {
@ -2663,7 +2663,7 @@ class DeleteHistoryQuery final : public Td::ResultHandler {
return on_error(result_ptr.move_as_error()); 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 { void on_error(Status status) final {
@ -2747,7 +2747,7 @@ class DeleteMessagesByDateQuery final : public Td::ResultHandler {
return on_error(result_ptr.move_as_error()); 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 { void on_error(Status status) final {
@ -2879,7 +2879,7 @@ class DeleteUserHistoryQuery final : public Td::ResultHandler {
return on_error(result_ptr.move_as_error()); 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 { void on_error(Status status) final {
@ -2913,7 +2913,7 @@ class ReadMentionsQuery final : public Td::ResultHandler {
return on_error(result_ptr.move_as_error()); 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 { void on_error(Status status) final {
@ -22463,25 +22463,25 @@ void MessagesManager::on_get_affected_history(DialogId dialog_id, AffectedHistor
Promise<Unit> &&promise) { Promise<Unit> &&promise) {
TRY_STATUS_PROMISE(promise, G()->close_status()); TRY_STATUS_PROMISE(promise, G()->close_status());
if (affected_history->pts_count_ > 0) { if (affected_history.pts_count_ > 0) {
if (get_affected_messages) { if (get_affected_messages) {
affected_history->pts_count_ = 0; affected_history.pts_count_ = 0;
} }
auto update_promise = affected_history->offset_ > 0 ? Promise<Unit>() : std::move(promise); auto update_promise = affected_history.is_final_ ? std::move(promise) : Promise<Unit>();
if (dialog_id.get_type() == DialogType::Channel) { if (dialog_id.get_type() == DialogType::Channel) {
td_->messages_manager_->add_pending_channel_update(dialog_id, make_tl_object<dummyUpdate>(), td_->messages_manager_->add_pending_channel_update(dialog_id, make_tl_object<dummyUpdate>(),
affected_history->pts_, affected_history->pts_count_, affected_history.pts_, affected_history.pts_count_,
std::move(update_promise), "on_get_affected_history"); std::move(update_promise), "on_get_affected_history");
} else { } else {
td_->updates_manager_->add_pending_pts_update(make_tl_object<dummyUpdate>(), affected_history->pts_, td_->updates_manager_->add_pending_pts_update(make_tl_object<dummyUpdate>(), affected_history.pts_,
affected_history->pts_count_, Time::now(), affected_history.pts_count_, Time::now(), std::move(update_promise),
std::move(update_promise), "on_get_affected_history"); "on_get_affected_history");
} }
} else if (affected_history->offset_ <= 0) { } else if (affected_history.is_final_) {
promise.set_value(Unit()); 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)); run_affected_history_query_until_complete(dialog_id, std::move(query), get_affected_messages, std::move(promise));
} }
} }

View File

@ -7,6 +7,7 @@
#pragma once #pragma once
#include "td/telegram/AccessRights.h" #include "td/telegram/AccessRights.h"
#include "td/telegram/AffectedHistory.h"
#include "td/telegram/ChannelId.h" #include "td/telegram/ChannelId.h"
#include "td/telegram/DialogAction.h" #include "td/telegram/DialogAction.h"
#include "td/telegram/DialogDate.h" #include "td/telegram/DialogDate.h"
@ -92,8 +93,6 @@ class MessageContent;
class MultiSequenceDispatcher; class MultiSequenceDispatcher;
class Td; class Td;
using AffectedHistory = tl_object_ptr<telegram_api::messages_affectedHistory>;
class MessagesManager final : public Actor { class MessagesManager final : public Actor {
public: public:
// static constexpr int32 MESSAGE_FLAG_IS_UNREAD = 1 << 0; // static constexpr int32 MESSAGE_FLAG_IS_UNREAD = 1 << 0;