diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 80afe0acf..3e2662daf 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3070,20 +3070,16 @@ std::shared_ptr Td::extract_handler(uint64 id) { return result; } -void Td::on_update(BufferSlice &&update, uint64 auth_key_id) { +void Td::on_update(telegram_api::object_ptr updates, uint64 auth_key_id) { if (close_flag_ > 1) { return; } - TlBufferParser parser(&update); - auto ptr = telegram_api::Updates::fetch(parser); - parser.fetch_end(); - if (parser.get_error()) { - LOG(ERROR) << "Failed to fetch update: " << parser.get_error() << format::as_hex_dump<4>(update.as_slice()); - updates_manager_->schedule_get_difference("failed to fetch update"); + if (updates == nullptr) { + updates_manager_->schedule_get_difference("failed to fetch updates"); } else { updates_manager_->on_update_from_auth_key_id(auth_key_id); - updates_manager_->on_get_updates(std::move(ptr), Promise()); + updates_manager_->on_get_updates(std::move(updates), Promise()); if (auth_manager_->is_bot() && auth_manager_->is_authorized()) { alarm_timeout_.set_timeout_in(PING_SERVER_ALARM_ID, PING_SERVER_TIMEOUT + Random::fast(0, PING_SERVER_TIMEOUT / 5)); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 3afd1b8c8..b4e8ff8a3 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -121,7 +121,7 @@ class Td final : public Actor { void reload_promo_data(); - void on_update(BufferSlice &&update, uint64 auth_key_id); + void on_update(telegram_api::object_ptr updates, uint64 auth_key_id); void on_result(NetQueryPtr query); diff --git a/td/telegram/net/SessionProxy.cpp b/td/telegram/net/SessionProxy.cpp index 36f4e702e..e46a609c0 100644 --- a/td/telegram/net/SessionProxy.cpp +++ b/td/telegram/net/SessionProxy.cpp @@ -14,10 +14,12 @@ #include "td/telegram/net/Session.h" #include "td/telegram/Td.h" #include "td/telegram/TdDb.h" +#include "td/telegram/telegram_api.h" #include "td/telegram/UniqueId.h" #include "td/utils/buffer.h" #include "td/utils/common.h" +#include "td/utils/format.h" #include "td/utils/HashTableUtils.h" #include "td/utils/logging.h" #include "td/utils/Promise.h" @@ -25,6 +27,7 @@ #include "td/utils/SliceBuilder.h" #include "td/utils/Time.h" #include "td/utils/tl_helpers.h" +#include "td/utils/tl_parsers.h" namespace td { @@ -63,7 +66,14 @@ class SessionCallback final : public Session::Callback { } void on_update(BufferSlice &&update, uint64 auth_key_id) final { - send_closure_later(G()->td(), &Td::on_update, std::move(update), auth_key_id); + TlBufferParser parser(&update); + auto updates = telegram_api::Updates::fetch(parser); + parser.fetch_end(); + if (parser.get_error()) { + LOG(ERROR) << "Failed to fetch update: " << parser.get_error() << format::as_hex_dump<4>(update.as_slice()); + updates = nullptr; + } + send_closure_later(G()->td(), &Td::on_update, std::move(updates), auth_key_id); } void on_result(NetQueryPtr query) final {