From 70cfbab277e1173c3772a65576ecfe2b0396b97c Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 2 Dec 2022 12:36:31 +0300 Subject: [PATCH] Extract only relevant random_id from updates. --- td/telegram/MessagesManager.cpp | 13 +++++++++---- td/telegram/MessagesManager.h | 2 ++ td/telegram/UpdatesManager.cpp | 20 ++++++++++++++------ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 19381287d..be129813d 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -13232,19 +13232,20 @@ void MessagesManager::on_update_viewed_messages_timeout(DialogId dialog_id) { update_viewed_messages_timeout_.add_timeout_in(dialog_id.get(), UPDATE_VIEWED_MESSAGES_PERIOD); } -MessageId MessagesManager::get_message_id(const tl_object_ptr &message_ptr, bool is_scheduled) { +MessageId MessagesManager::get_message_id(const telegram_api::Message *message_ptr, bool is_scheduled) { + CHECK(message_ptr != nullptr) switch (message_ptr->get_id()) { case telegram_api::messageEmpty::ID: { - auto message = static_cast(message_ptr.get()); + auto message = static_cast(message_ptr); return is_scheduled ? MessageId() : MessageId(ServerMessageId(message->id_)); } case telegram_api::message::ID: { - auto message = static_cast(message_ptr.get()); + auto message = static_cast(message_ptr); return is_scheduled ? MessageId(ScheduledServerMessageId(message->id_), message->date_) : MessageId(ServerMessageId(message->id_)); } case telegram_api::messageService::ID: { - auto message = static_cast(message_ptr.get()); + auto message = static_cast(message_ptr); return is_scheduled ? MessageId(ScheduledServerMessageId(message->id_), message->date_) : MessageId(ServerMessageId(message->id_)); } @@ -13254,6 +13255,10 @@ MessageId MessagesManager::get_message_id(const tl_object_ptr &message_ptr, bool is_scheduled) { + return get_message_id(message_ptr.get(), is_scheduled); +} + DialogId MessagesManager::get_message_dialog_id(const telegram_api::Message *message_ptr) { CHECK(message_ptr != nullptr); switch (message_ptr->get_id()) { diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index bea734ba0..4cb172d01 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -165,6 +165,8 @@ class MessagesManager final : public Actor { static vector get_scheduled_server_message_ids(const vector &message_ids); + static MessageId get_message_id(const telegram_api::Message *message_ptr, bool is_scheduled); + static MessageId get_message_id(const tl_object_ptr &message_ptr, bool is_scheduled); static DialogId get_message_dialog_id(const telegram_api::Message *message_ptr); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 39745d32a..a7cbb4249 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -1149,12 +1149,20 @@ FlatHashSet UpdatesManager::get_sent_messages_random_ids(const telegram_a auto new_messages = get_new_messages(updates_ptr); for (auto &update : *updates) { if (update->get_id() == telegram_api::updateMessageID::ID) { - int64 random_id = static_cast(update.get())->random_id_; + auto update_message_id = static_cast(update.get()); + int64 random_id = update_message_id->random_id_; if (random_id != 0) { - bool found_message = true; - // for (auto *message : new_messages) { - // TODO - // } + bool found_message = false; + for (auto message : new_messages) { + MessageId message_id = MessagesManager::get_message_id(message.first, message.second); + if (message.second) { + found_message |= message_id.is_valid_scheduled() && + message_id.get_scheduled_server_message_id().get() == update_message_id->id_; + } else { + found_message |= + message_id.is_valid() && message_id.get_server_message_id().get() == update_message_id->id_; + } + } if (found_message && !random_ids.insert(random_id).second) { LOG(ERROR) << "Receive twice updateMessageID for " << random_id; } @@ -1234,7 +1242,7 @@ vector> UpdatesManager::get_new_m is_scheduled = true; } - if (is_additional_service_message(message)) { + if (message != nullptr && !is_additional_service_message(message)) { messages.emplace_back(message, is_scheduled); } }