diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 244ef291..7828f387 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -853,7 +853,7 @@ pageBlockCover cover:PageBlock = PageBlock; //@description An embedded web page @url Web page URL, if available @html HTML-markup of the embedded page @poster_photo Poster photo, if available; may be null @width Block width, 0 if unknown @height Block height, 0 if unknown @caption Block caption @is_full_width True, if the block should be full width @allow_scrolling True, if scrolling should be allowed pageBlockEmbedded url:string html:string poster_photo:photo width:int32 height:int32 caption:pageBlockCaption is_full_width:Bool allow_scrolling:Bool = PageBlock; -//@description An embedded post @url Web page URL @author Post author @author_photo Post author photo @date Point in time (Unix timestamp) when the post was created; 0 if unknown @page_blocks Post content @caption Post caption +//@description An embedded post @url Web page URL @author Post author @author_photo Post author photo; may be null @date Point in time (Unix timestamp) when the post was created; 0 if unknown @page_blocks Post content @caption Post caption pageBlockEmbeddedPost url:string author:string author_photo:photo date:int32 page_blocks:vector caption:pageBlockCaption = PageBlock; //@description A collage @page_blocks Collage item contents @caption Block caption diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index e7c5e96b..98078d7f 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -6544,19 +6544,12 @@ void ContactsManager::on_get_user_full(tl_object_ptr &&u user->is_changed = true; } - int32 photo_id = - user_full->profile_photo_ == nullptr ? telegram_api::photoEmpty::ID : user_full->profile_photo_->get_id(); - if (photo_id == telegram_api::photoEmpty::ID) { + Photo photo = get_photo(td_->file_manager_.get(), std::move(user_full->profile_photo_), DialogId()); + if (photo.id == -2) { user->photo_count = 0; user->photos_offset = 0; user->photos.clear(); - } else { - CHECK(photo_id == telegram_api::photo::ID); - - // Photo profile_photo = - // get_photo(td_->file_manager_.get(), move_tl_object_as(user_full->profile_photo_)); } - if ((user_full->flags_ & USER_FULL_FLAG_HAS_BOT_INFO) != 0 && !u->is_deleted) { on_update_user_full_bot_info(user, user_id, u->bot_info_version, std::move(user_full->bot_info_)); } @@ -6585,12 +6578,14 @@ void ContactsManager::on_get_user_photos(UserId user_id, int32 offset, int32 lim for (auto &photo_ptr : photos) { if (photo_ptr->get_id() == telegram_api::photo::ID) { auto server_photo = telegram_api::move_object_as(photo_ptr); - auto profile_photo = convert_photo_to_profile_photo(server_photo); - if (profile_photo) { - LOG_IF(ERROR, u->access_hash == -1) << "Receive profile photo of " << user_id << " without access hash"; - get_profile_photo(td_->file_manager_.get(), user_id, u->access_hash, std::move(profile_photo)); - } else { - LOG(ERROR) << "Failed to get profile photo from " << to_string(server_photo); + if (server_photo->id_ == u->photo.id) { + auto profile_photo = convert_photo_to_profile_photo(server_photo); + if (profile_photo) { + LOG_IF(ERROR, u->access_hash == -1) << "Receive profile photo of " << user_id << " without access hash"; + get_profile_photo(td_->file_manager_.get(), user_id, u->access_hash, std::move(profile_photo)); + } else { + LOG(ERROR) << "Failed to get profile photo from " << to_string(server_photo); + } } auto photo = get_photo(td_->file_manager_.get(), std::move(server_photo), DialogId()); @@ -6618,17 +6613,15 @@ void ContactsManager::on_get_user_photos(UserId user_id, int32 offset, int32 lim } for (auto &photo : photos) { - int32 photo_id = photo->get_id(); - if (photo_id == telegram_api::photoEmpty::ID) { + auto user_photo = get_photo(td_->file_manager_.get(), std::move(photo), DialogId()); + if (user_photo.id == -2) { LOG(ERROR) << "Have got empty profile photo in getUserPhotos request for " << user_id << " with offset " << offset << " and limit " << limit << ". Receive " << photo_count << " photos out of " << total_count << " photos"; continue; } - CHECK(photo_id == telegram_api::photo::ID); - user->photos.push_back( - get_photo(td_->file_manager_.get(), telegram_api::move_object_as(photo), DialogId())); + user->photos.push_back(std::move(user_photo)); add_user_photo_id(u, user_id, user->photos.back().id, photo_get_file_ids(user->photos.back())); } } diff --git a/td/telegram/Game.cpp b/td/telegram/Game.cpp index 2eddd996..75866fab 100644 --- a/td/telegram/Game.cpp +++ b/td/telegram/Game.cpp @@ -35,8 +35,10 @@ Game::Game(Td *td, string title, string description, tl_object_ptrget_id() == telegram_api::photo::ID) { - photo_ = get_photo(td->file_manager_.get(), move_tl_object_as(photo), owner_dialog_id); + photo_ = get_photo(td->file_manager_.get(), std::move(photo), owner_dialog_id); + if (photo_.id == -2) { + LOG(ERROR) << "Receive empty photo for game " << title; + photo_.id = 0; // to prevent null photo in td_api } if (document != nullptr) { int32 document_id = document->get_id(); diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index 8f7f23d5..c83c9f43 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -1268,15 +1268,11 @@ void InlineQueriesManager::on_get_inline_query_results(UserId bot_user_id, uint6 LOG_IF(ERROR, !is_photo) << "Wrong result type " << result->type_; auto photo = make_tl_object(); photo->id_ = std::move(result->id_); - auto photo_ptr = std::move(result->photo_); - int32 photo_id = photo_ptr->get_id(); - if (photo_id == telegram_api::photoEmpty::ID) { + Photo p = get_photo(td_->file_manager_.get(), std::move(result->photo_), DialogId()); + if (p.id == -2) { LOG(ERROR) << "Receive empty cached photo in the result of inline query"; break; } - CHECK(photo_id == telegram_api::photo::ID); - - Photo p = get_photo(td_->file_manager_.get(), move_tl_object_as(photo_ptr), DialogId()); photo->photo_ = get_photo_object(td_->file_manager_.get(), &p); photo->title_ = std::move(result->title_); photo->description_ = std::move(result->description_); diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 338616eb..9977007b 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -3760,19 +3760,15 @@ unique_ptr get_message_content(Td *td, FormattedText message, return make_unique(); } - auto photo_ptr = std::move(message_photo->photo_); - int32 photo_id = photo_ptr->get_id(); - if (photo_id == telegram_api::photoEmpty::ID) { + auto photo = get_photo(td->file_manager_.get(), std::move(message_photo->photo_), owner_dialog_id); + if (photo.id == -2) { return make_unique(); } - CHECK(photo_id == telegram_api::photo::ID); if (ttl != nullptr && (message_photo->flags_ & telegram_api::messageMediaPhoto::TTL_SECONDS_MASK) != 0) { *ttl = message_photo->ttl_seconds_; } - return make_unique( - get_photo(td->file_manager_.get(), move_tl_object_as(photo_ptr), owner_dialog_id), - std::move(message)); + return make_unique(std::move(photo), std::move(message)); } case telegram_api::messageMediaGeo::ID: { auto message_geo_point = move_tl_object_as(media); @@ -4130,16 +4126,11 @@ unique_ptr get_action_message_content(Td *td, tl_object_ptr(action); - - auto photo_ptr = std::move(chat_edit_photo->photo_); - int32 photo_id = photo_ptr->get_id(); - if (photo_id == telegram_api::photoEmpty::ID) { + auto photo = get_photo(td->file_manager_.get(), std::move(chat_edit_photo->photo_), owner_dialog_id); + if (photo.id == -2) { break; } - CHECK(photo_id == telegram_api::photo::ID); - - return make_unique( - get_photo(td->file_manager_.get(), move_tl_object_as(photo_ptr), owner_dialog_id)); + return make_unique(std::move(photo)); } case telegram_api::messageActionChatDeletePhoto::ID: { return make_unique(); diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index 9ecc118e..74fc9a5e 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -552,6 +552,11 @@ Photo get_photo(FileManager *file_manager, tl_object_ptr && res.date = photo->date_; res.has_stickers = (photo->flags_ & telegram_api::photo::HAS_STICKERS_MASK) != 0; + if (res.id == -2) { + LOG(ERROR) << "Receive photo with id " << res.id; + res.id = -3; + } + for (auto &size_ptr : photo->sizes_) { auto photo_size = get_photo_size(file_manager, {FileType::Photo, 0}, photo->id_, photo->access_hash_, photo->file_reference_.as_slice().str(), DcId::create(photo->dc_id_), diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index fcd58121..73796fa6 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -441,12 +441,7 @@ WebPageId WebPagesManager::on_get_web_page(tl_object_ptr page->site_name = std::move(web_page->site_name_); page->title = std::move(web_page->title_); page->description = std::move(web_page->description_); - if ((web_page->flags_ & WEBPAGE_FLAG_HAS_PHOTO) && web_page->photo_->get_id() == telegram_api::photo::ID) { - page->photo = get_photo(td_->file_manager_.get(), move_tl_object_as(web_page->photo_), - owner_dialog_id); - } else { - page->photo.id = -2; - } + page->photo = get_photo(td_->file_manager_.get(), std::move(web_page->photo_), owner_dialog_id); if (web_page->flags_ & WEBPAGE_FLAG_HAS_EMBEDDED_PREVIEW) { page->embed_url = std::move(web_page->embed_url_); page->embed_type = std::move(web_page->embed_type_); @@ -1188,11 +1183,11 @@ void WebPagesManager::on_get_web_page_instant_view(WebPage *web_page, tl_object_ CHECK(page != nullptr); std::unordered_map photos; for (auto &photo_ptr : page->photos_) { - if (photo_ptr->get_id() == telegram_api::photo::ID) { - Photo photo = - get_photo(td_->file_manager_.get(), move_tl_object_as(photo_ptr), owner_dialog_id); - int64 photo_id = photo.id; - photos.emplace(photo_id, std::move(photo)); + Photo photo = get_photo(td_->file_manager_.get(), std::move(photo_ptr), owner_dialog_id); + if (photo.id == -2 || photo.id == 0) { + LOG(ERROR) << "Receive empty photo in web page instant view for " << web_page->url; + } else { + photos.emplace(photo.id, std::move(photo)); } } if (web_page->photo.id != -2 && web_page->photo.id != 0) {