Use get_photo(telegram_api::Photo) whenever possible.

GitOrigin-RevId: 6ab86f8a10f8a80584cd7a4ada4fbbda19df9d96
This commit is contained in:
levlam 2019-06-17 02:41:57 +03:00
parent e91da22a5b
commit cf4433dc52
7 changed files with 37 additions and 55 deletions

View File

@ -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<PageBlock> caption:pageBlockCaption = PageBlock;
//@description A collage @page_blocks Collage item contents @caption Block caption

View File

@ -6544,19 +6544,12 @@ void ContactsManager::on_get_user_full(tl_object_ptr<telegram_api::userFull> &&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<telegram_api::photo>(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<telegram_api::photo>(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<telegram_api::photo>(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()));
}
}

View File

@ -35,8 +35,10 @@ Game::Game(Td *td, string title, string description, tl_object_ptr<telegram_api:
: title_(std::move(title)), description_(std::move(description)) {
CHECK(td != nullptr);
CHECK(photo != nullptr);
if (photo->get_id() == telegram_api::photo::ID) {
photo_ = get_photo(td->file_manager_.get(), move_tl_object_as<telegram_api::photo>(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();

View File

@ -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<td_api::inlineQueryResultPhoto>();
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<telegram_api::photo>(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_);

View File

@ -3760,19 +3760,15 @@ unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message,
return make_unique<MessageExpiredPhoto>();
}
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<MessageExpiredPhoto>();
}
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<MessagePhoto>(
get_photo(td->file_manager_.get(), move_tl_object_as<telegram_api::photo>(photo_ptr), owner_dialog_id),
std::move(message));
return make_unique<MessagePhoto>(std::move(photo), std::move(message));
}
case telegram_api::messageMediaGeo::ID: {
auto message_geo_point = move_tl_object_as<telegram_api::messageMediaGeo>(media);
@ -4130,16 +4126,11 @@ unique_ptr<MessageContent> get_action_message_content(Td *td, tl_object_ptr<tele
}
case telegram_api::messageActionChatEditPhoto::ID: {
auto chat_edit_photo = move_tl_object_as<telegram_api::messageActionChatEditPhoto>(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<MessageChatChangePhoto>(
get_photo(td->file_manager_.get(), move_tl_object_as<telegram_api::photo>(photo_ptr), owner_dialog_id));
return make_unique<MessageChatChangePhoto>(std::move(photo));
}
case telegram_api::messageActionChatDeletePhoto::ID: {
return make_unique<MessageChatDeletePhoto>();

View File

@ -552,6 +552,11 @@ Photo get_photo(FileManager *file_manager, tl_object_ptr<telegram_api::photo> &&
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_),

View File

@ -441,12 +441,7 @@ WebPageId WebPagesManager::on_get_web_page(tl_object_ptr<telegram_api::WebPage>
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<telegram_api::photo>(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<int64, Photo> 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<telegram_api::photo>(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) {