From 2eacc1f9741f8f93bedf9741eba37ce49689efaf Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 15 Jan 2021 18:45:26 +0300 Subject: [PATCH] Forcely process pts updates in process_updates. --- td/telegram/UpdatesManager.cpp | 83 ++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index c6d5f3812..a9337ce56 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -1135,7 +1135,7 @@ void UpdatesManager::process_get_difference_updates( } if (constructor_id == telegram_api::updateEncryption::ID) { - on_update(move_tl_object_as(update), true, Promise()); + on_update(move_tl_object_as(update), false, Promise()); CHECK(!running_get_difference_); } @@ -1143,9 +1143,10 @@ void UpdatesManager::process_get_difference_updates( auto update_folder_peers = move_tl_object_as(update); if (update_folder_peers->pts_count_ != 0) { LOG(ERROR) << "Receive updateFolderPeers with pts_count = " << update_folder_peers->pts_count_; + update_folder_peers->pts_count_ = 0; } update_folder_peers->pts_ = 0; - on_update(std::move(update_folder_peers), true, Promise()); + on_update(std::move(update_folder_peers), false, Promise()); CHECK(!running_get_difference_); } @@ -1153,7 +1154,8 @@ void UpdatesManager::process_get_difference_updates( // TODO can't apply it here, because dialog may not be created yet // process updateReadHistoryInbox before new messages if (constructor_id == telegram_api::updateReadHistoryInbox::ID) { - on_update(move_tl_object_as(update), true, Promise()); + static_cast(update.get())->still_unread_count_ = -1; + td_->messages_manager_->process_pts_update(std::move(update)); CHECK(!running_get_difference_); } */ @@ -1627,7 +1629,7 @@ void UpdatesManager::process_updates(vector> // process updateReadChannelInbox before updateNewChannelMessage auto constructor_id = update->get_id(); if (constructor_id == telegram_api::updateReadChannelInbox::ID) { - on_update(move_tl_object_as(update), force_apply, mpas.get_promise()); + on_update(move_tl_object_as(update), false, mpas.get_promise()); } } } @@ -1637,17 +1639,41 @@ void UpdatesManager::process_updates(vector> // process updateNewChannelMessage first auto constructor_id = update->get_id(); if (constructor_id == telegram_api::updateNewChannelMessage::ID) { - on_update(move_tl_object_as(update), force_apply, mpas.get_promise()); + on_update(move_tl_object_as(update), false, mpas.get_promise()); + continue; } // process updateNewScheduledMessage first if (constructor_id == telegram_api::updateNewScheduledMessage::ID) { - on_update(move_tl_object_as(update), force_apply, mpas.get_promise()); + on_update(move_tl_object_as(update), false, mpas.get_promise()); + continue; } // updatePtsChanged forces get difference, so process it last if (constructor_id == telegram_api::updatePtsChanged::ID) { update_pts_changed = move_tl_object_as(update); + continue; + } + } + } + if (force_apply) { + // forcely process pts updates + for (auto &update : updates) { + if (update != nullptr && is_pts_update(update.get())) { + auto constructor_id = update->get_id(); + if (constructor_id == telegram_api::updateWebPage::ID) { + auto update_web_page = move_tl_object_as(update); + td_->web_pages_manager_->on_get_web_page(std::move(update_web_page->webpage_), DialogId()); + continue; + } + + CHECK(constructor_id != telegram_api::updateFolderPeers::ID); + + if (constructor_id == telegram_api::updateReadHistoryInbox::ID) { + static_cast(update.get())->still_unread_count_ = -1; + } + + td_->messages_manager_->process_pts_update(std::move(update)); } } } @@ -1662,7 +1688,7 @@ void UpdatesManager::process_updates(vector> } } if (update_pts_changed != nullptr) { - on_update(std::move(update_pts_changed), force_apply, mpas.get_promise()); + on_update(std::move(update_pts_changed), false, mpas.get_promise()); } lock.set_value(Unit()); } @@ -1804,10 +1830,7 @@ void UpdatesManager::on_update(tl_object_ptr upd Promise &&promise) { int new_pts = update->pts_; int pts_count = update->pts_count_; - if (force_apply) { - td_->messages_manager_->process_pts_update(std::move(update)); - return promise.set_value(Unit()); - } + CHECK(!force_apply); td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, std::move(promise), "updateNewMessage"); } @@ -1837,10 +1860,7 @@ void UpdatesManager::on_update(tl_object_ptr &&promise) { int new_pts = update->pts_; int pts_count = update->pts_count_; - if (force_apply) { - td_->messages_manager_->process_pts_update(std::move(update)); - return promise.set_value(Unit()); - } + CHECK(!force_apply); td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, std::move(promise), "updateReadMessagesContents"); } @@ -1849,10 +1869,7 @@ void UpdatesManager::on_update(tl_object_ptr up Promise &&promise) { int new_pts = update->pts_; int pts_count = update->pts_count_; - if (force_apply) { - td_->messages_manager_->process_pts_update(std::move(update)); - return promise.set_value(Unit()); - } + CHECK(!force_apply); td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, std::move(promise), "updateEditMessage"); } @@ -1861,10 +1878,7 @@ void UpdatesManager::on_update(tl_object_ptr Promise &&promise) { int new_pts = update->pts_; int pts_count = update->pts_count_; - if (force_apply) { - td_->messages_manager_->process_pts_update(std::move(update)); - return promise.set_value(Unit()); - } + CHECK(!force_apply); if (update->messages_.empty()) { td_->messages_manager_->add_pending_update(make_tl_object(), new_pts, pts_count, Promise(), "updateDeleteMessages"); @@ -1879,11 +1893,7 @@ void UpdatesManager::on_update(tl_object_ptr &&promise) { int new_pts = update->pts_; int pts_count = update->pts_count_; - if (force_apply) { - update->still_unread_count_ = -1; - td_->messages_manager_->process_pts_update(std::move(update)); - return promise.set_value(Unit()); - } + CHECK(!force_apply); td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, std::move(promise), "updateReadHistoryInbox"); } @@ -1892,10 +1902,7 @@ void UpdatesManager::on_update(tl_object_ptr &&promise) { int new_pts = update->pts_; int pts_count = update->pts_count_; - if (force_apply) { - td_->messages_manager_->process_pts_update(std::move(update)); - return promise.set_value(Unit()); - } + CHECK(!force_apply); td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, std::move(promise), "updateReadHistoryOutbox"); } @@ -2020,10 +2027,7 @@ void UpdatesManager::on_update(tl_object_ptr Promise &&promise) { int new_pts = update->pts_; int pts_count = update->pts_count_; - if (force_apply) { - td_->messages_manager_->process_pts_update(std::move(update)); - return promise.set_value(Unit()); - } + CHECK(!force_apply); td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, std::move(promise), "updatePinnedMessages"); } @@ -2083,10 +2087,9 @@ void UpdatesManager::on_update(tl_object_ptr up void UpdatesManager::on_update(tl_object_ptr update, bool force_apply, Promise &&promise) { td_->web_pages_manager_->on_get_web_page(std::move(update->webpage_), DialogId()); - if (!force_apply) { - td_->messages_manager_->add_pending_update(make_tl_object(), update->pts_, update->pts_count_, - Promise(), "updateWebPage"); - } + CHECK(!force_apply); + td_->messages_manager_->add_pending_update(make_tl_object(), update->pts_, update->pts_count_, + Promise(), "updateWebPage"); promise.set_value(Unit()); }