Improve pts extraction from updates.

This commit is contained in:
levlam 2022-02-16 21:18:36 +03:00
parent b2077f72e4
commit 24d2505f5b
4 changed files with 23 additions and 9 deletions

View File

@ -3645,6 +3645,7 @@ class SendScheduledMessageQuery final : public Td::ResultHandler {
class EditMessageQuery final : public Td::ResultHandler {
Promise<int32> promise_;
DialogId dialog_id_;
MessageId message_id_;
public:
explicit EditMessageQuery(Promise<Unit> &&promise) {
@ -3664,6 +3665,7 @@ class EditMessageQuery final : public Td::ResultHandler {
tl_object_ptr<telegram_api::InputMedia> &&input_media,
tl_object_ptr<telegram_api::ReplyMarkup> &&reply_markup, int32 schedule_date) {
dialog_id_ = dialog_id;
message_id_ = message_id;
if (input_media != nullptr && false) {
return on_error(Status::Error(400, "FILE_PART_1_MISSING"));
@ -3707,7 +3709,7 @@ class EditMessageQuery final : public Td::ResultHandler {
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for EditMessageQuery: " << to_string(ptr);
auto pts = td_->updates_manager_->get_update_edit_message_pts(ptr.get());
auto pts = td_->updates_manager_->get_update_edit_message_pts(ptr.get(), {dialog_id_, message_id_});
auto promise = PromiseCreator::lambda(
[promise = std::move(promise_), pts](Result<Unit> result) mutable { promise.set_value(std::move(pts)); });
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise));

View File

@ -158,6 +158,8 @@ class MessagesManager final : public Actor {
static DialogId get_message_dialog_id(const tl_object_ptr<telegram_api::Message> &message_ptr);
static FullMessageId get_full_message_id(const tl_object_ptr<telegram_api::Message> &message_ptr, bool is_scheduled);
tl_object_ptr<telegram_api::InputPeer> get_input_peer(DialogId dialog_id, AccessRights access_rights) const;
static tl_object_ptr<telegram_api::InputPeer> get_input_peer_force(DialogId dialog_id);
@ -1781,8 +1783,6 @@ class MessagesManager final : public Actor {
static constexpr bool DROP_SEND_MESSAGE_UPDATES = false;
static FullMessageId get_full_message_id(const tl_object_ptr<telegram_api::Message> &message_ptr, bool is_scheduled);
static int32 get_message_date(const tl_object_ptr<telegram_api::Message> &message_ptr);
static bool is_dialog_inited(const Dialog *d);

View File

@ -1204,17 +1204,28 @@ vector<DialogId> UpdatesManager::get_chat_dialog_ids(const telegram_api::Updates
return dialog_ids;
}
int32 UpdatesManager::get_update_edit_message_pts(const telegram_api::Updates *updates_ptr) {
int32 UpdatesManager::get_update_edit_message_pts(const telegram_api::Updates *updates_ptr,
FullMessageId full_message_id) {
int32 pts = 0;
auto updates = get_updates(updates_ptr);
if (updates != nullptr) {
for (auto &update : *updates) {
int32 update_pts = [&] {
switch (update->get_id()) {
case telegram_api::updateEditMessage::ID:
return static_cast<const telegram_api::updateEditMessage *>(update.get())->pts_;
case telegram_api::updateEditChannelMessage::ID:
return static_cast<const telegram_api::updateEditChannelMessage *>(update.get())->pts_;
case telegram_api::updateEditMessage::ID: {
auto update_ptr = static_cast<const telegram_api::updateEditMessage *>(update.get());
if (MessagesManager::get_full_message_id(update_ptr->message_, false) == full_message_id) {
return update_ptr->pts_;
}
return 0;
}
case telegram_api::updateEditChannelMessage::ID: {
auto update_ptr = static_cast<const telegram_api::updateEditChannelMessage *>(update.get());
if (MessagesManager::get_full_message_id(update_ptr->message_, false) == full_message_id) {
return update_ptr->pts_;
}
return 0;
}
default:
return 0;
}

View File

@ -9,6 +9,7 @@
#include "td/telegram/ChannelId.h"
#include "td/telegram/ChatId.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/FullMessageId.h"
#include "td/telegram/InputGroupCallId.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/PtsManager.h"
@ -111,7 +112,7 @@ class UpdatesManager final : public Actor {
static vector<DialogId> get_chat_dialog_ids(const telegram_api::Updates *updates_ptr);
static int32 get_update_edit_message_pts(const telegram_api::Updates *updates_ptr);
static int32 get_update_edit_message_pts(const telegram_api::Updates *updates_ptr, FullMessageId full_message_id);
void get_difference(const char *source);