From a599557c9d40f2180a9665b64f8959276cd49357 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 30 Mar 2020 01:48:44 +0300 Subject: [PATCH] Support some updates before authorization. GitOrigin-RevId: 21bd7a06bf41ebc81005b35a0695988d82e6b4a3 --- td/telegram/MessageContent.cpp | 5 +++++ td/telegram/MessagesManager.cpp | 16 +++++++++------- td/telegram/UpdatesManager.cpp | 23 +++++++++++++++++++---- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 16c880c84..4b291875d 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -3675,6 +3675,11 @@ unique_ptr get_message_content(Td *td, FormattedText message, tl_object_ptr &&media, DialogId owner_dialog_id, bool is_content_read, UserId via_bot_user_id, int32 *ttl) { + if (!td->auth_manager_->is_authorized() && !G()->close_flag() && media != nullptr) { + LOG(ERROR) << "Receive without authorization " << to_string(media); + media = nullptr; + } + int32 constructor_id = media == nullptr ? telegram_api::messageMediaEmpty::ID : media->get_id(); switch (constructor_id) { case telegram_api::messageMediaEmpty::ID: diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 3e64521db..55649ad14 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -5468,12 +5468,14 @@ void MessagesManager::on_update_service_notification(tl_object_ptrcontacts_manager_.get(), std::move(update->message_), std::move(update->entities_), - skip_new_entities, date, false, "on_update_service_notification"); - auto content = get_message_content( - td_, std::move(message_text), std::move(update->media_), - td_->auth_manager_->is_bot() ? DialogId() : get_service_notifications_dialog()->dialog_id, false, UserId(), &ttl); + bool is_authorized = td_->auth_manager_->is_authorized(); + bool is_user = is_authorized && !td_->auth_manager_->is_bot(); + auto contacts_manager = is_authorized ? td_->contacts_manager_.get() : nullptr; + auto message_text = get_message_text(contacts_manager, std::move(update->message_), std::move(update->entities_), + skip_new_entities, date, false, "on_update_service_notification"); + DialogId owner_dialog_id = is_user ? get_service_notifications_dialog()->dialog_id : DialogId(); + auto content = get_message_content(td_, std::move(message_text), std::move(update->media_), owner_dialog_id, false, + UserId(), &ttl); bool is_content_secret = is_secret_message_content(ttl, content->get_type()); if ((update->flags_ & telegram_api::updateServiceNotification::POPUP_MASK) != 0) { @@ -5481,7 +5483,7 @@ void MessagesManager::on_update_service_notification(tl_object_ptr( update->type_, get_message_content_object(content.get(), td_, date, is_content_secret))); } - if (has_date && !td_->auth_manager_->is_bot()) { + if (has_date && is_user) { Dialog *d = get_service_notifications_dialog(); CHECK(d != nullptr); auto dialog_id = d->dialog_id; diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index f4017b95b..b8337daa6 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -638,10 +638,25 @@ void UpdatesManager::on_get_updates(tl_object_ptr &&updat LOG(INFO) << "Receive " << to_string(updates_ptr); } if (!td_->auth_manager_->is_authorized()) { - if (updates_type == telegram_api::updateShort::ID && - static_cast(updates_ptr.get())->update_->get_id() == - telegram_api::updateLoginToken::ID) { - return td_->auth_manager_->on_update_login_token(); + if (updates_type == telegram_api::updateShort::ID && !G()->close_flag()) { + auto &update = static_cast(updates_ptr.get())->update_; + auto update_id = update->get_id(); + if (update_id == telegram_api::updateLoginToken::ID) { + return td_->auth_manager_->on_update_login_token(); + } + + switch (update_id) { + case telegram_api::updateServiceNotification::ID: + case telegram_api::updateDcOptions::ID: + case telegram_api::updateConfig::ID: + case telegram_api::updateLangPackTooLong::ID: + case telegram_api::updateLangPack::ID: + LOG(INFO) << "Apply without authorization " << to_string(updates_ptr); + downcast_call(*update, OnUpdate(this, update, false)); + return; + default: + break; + } } LOG(INFO) << "Ignore received before authorization or after logout " << to_string(updates_ptr); return;