Support some updates before authorization.

GitOrigin-RevId: 21bd7a06bf41ebc81005b35a0695988d82e6b4a3
This commit is contained in:
levlam 2020-03-30 01:48:44 +03:00
parent 12a6bc9c04
commit a599557c9d
3 changed files with 33 additions and 11 deletions

View File

@ -3675,6 +3675,11 @@ unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message,
tl_object_ptr<telegram_api::MessageMedia> &&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:

View File

@ -5468,12 +5468,14 @@ void MessagesManager::on_update_service_notification(tl_object_ptr<telegram_api:
old_date = date;
}
auto message_text =
get_message_text(td_->contacts_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<telegram_api:
td_api::make_object<td_api::updateServiceNotification>(
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;

View File

@ -638,10 +638,25 @@ void UpdatesManager::on_get_updates(tl_object_ptr<telegram_api::Updates> &&updat
LOG(INFO) << "Receive " << to_string(updates_ptr);
}
if (!td_->auth_manager_->is_authorized()) {
if (updates_type == telegram_api::updateShort::ID &&
static_cast<const telegram_api::updateShort *>(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<telegram_api::updateShort *>(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;