diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index a2ac95e42..390cb7c2b 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -3241,6 +3241,7 @@ template void ContactsManager::UserFull::store(StorerT &storer) const { using td::store; bool has_about = !about.empty(); + bool has_photo = photo.id != -2; BEGIN_STORE_FLAGS(); STORE_FLAG(has_about); STORE_FLAG(is_blocked); @@ -3248,18 +3249,23 @@ void ContactsManager::UserFull::store(StorerT &storer) const { STORE_FLAG(has_private_calls); STORE_FLAG(can_pin_messages); STORE_FLAG(need_phone_number_privacy_exception); + STORE_FLAG(has_photo); END_STORE_FLAGS(); if (has_about) { store(about, storer); } store(common_chat_count, storer); store_time(expires_at, storer); + if (has_photo) { + store(photo, storer); + } } template void ContactsManager::UserFull::parse(ParserT &parser) { using td::parse; bool has_about; + bool has_photo; BEGIN_PARSE_FLAGS(); PARSE_FLAG(has_about); PARSE_FLAG(is_blocked); @@ -3267,12 +3273,16 @@ void ContactsManager::UserFull::parse(ParserT &parser) { PARSE_FLAG(has_private_calls); PARSE_FLAG(can_pin_messages); PARSE_FLAG(need_phone_number_privacy_exception); + PARSE_FLAG(has_photo); END_PARSE_FLAGS(); if (has_about) { parse(about, parser); } parse(common_chat_count, parser); parse_time(expires_at, parser); + if (has_photo) { + parse(photo, parser); + } } template @@ -9742,7 +9752,6 @@ void ContactsManager::drop_user_photos(UserId user_id, bool is_empty, bool drop_ if (is_empty) { if (user_full->photo.id != -2) { user_full->photo = Photo(); - user_full->photo.id = -2; user_full->is_changed = true; } } else { @@ -9773,7 +9782,6 @@ void ContactsManager::drop_user_full(UserId user_id) { user_full->expires_at = 0.0; user_full->photo = Photo(); - user_full->photo.id = -2; user_full->is_blocked = false; user_full->can_be_called = false; user_full->has_private_calls = false; diff --git a/td/telegram/Game.cpp b/td/telegram/Game.cpp index 36e37dfaf..c6ceac21e 100644 --- a/td/telegram/Game.cpp +++ b/td/telegram/Game.cpp @@ -58,6 +58,7 @@ Game::Game(UserId bot_user_id, string short_name) : bot_user_id_(bot_user_id), s if (!bot_user_id_.is_valid()) { bot_user_id_ = UserId(); } + photo_.id = 0; // to prevent null photo in td_api } bool Game::empty() const { diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index 9791b7aa2..2a0be4674 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -1421,6 +1421,7 @@ void InlineQueriesManager::on_get_inline_query_results(UserId bot_user_id, uint6 } Photo new_photo; + new_photo.id = 0; PhotoSize thumbnail = get_web_document_photo_size(td_->file_manager_.get(), FileType::Thumbnail, DialogId(), std::move(result->thumb_)); if (thumbnail.file_id.is_valid() && thumbnail.type != 'v' && thumbnail.type != 'g') { diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index e7f4a2dda..549692bf5 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -1529,6 +1529,8 @@ static Result create_input_message_content( if (file_view.has_remote_location() && !file_view.remote_location().is_web()) { message_photo->photo.id = file_view.remote_location().get_id(); + } else { + message_photo->photo.id = 0; } message_photo->photo.date = G()->unix_time(); int32 type = 'i'; @@ -1673,13 +1675,11 @@ static Result create_input_message_content( if (!input_invoice->photo_url_.empty()) { LOG(INFO) << "Can't register url " << input_invoice->photo_url_; } - message_invoice->photo.id = -2; } else { auto url = r_http_url.ok().get_url(); auto r_invoice_file_id = td->file_manager_->from_persistent_id(url, FileType::Temp); if (r_invoice_file_id.is_error()) { LOG(INFO) << "Can't register url " << url; - message_invoice->photo.id = -2; } else { auto invoice_file_id = r_invoice_file_id.move_as_ok(); @@ -1689,6 +1689,7 @@ static Result create_input_message_content( s.size = input_invoice->photo_size_; // TODO use invoice_file_id size s.file_id = invoice_file_id; + message_invoice->photo.id = 0; message_invoice->photo.photos.push_back(s); } } diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index 72258d1fe..44eabee94 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -3258,7 +3258,6 @@ Status NotificationManager::process_push_notification_payload(string payload, bo } Photo attached_photo; - attached_photo.id = -2; Document attached_document; if (has_json_object_field(custom, "attachb64")) { TRY_RESULT(attachb64, get_json_object_string_field(custom, "attachb64", false)); @@ -3510,8 +3509,6 @@ class NotificationManager::AddMessagePushNotificationLogEvent { } if (has_photo) { td::parse(photo_, parser); - } else { - photo_.id = -2; } if (has_document) { td::parse(document_, parser); @@ -3681,8 +3678,6 @@ class NotificationManager::EditMessagePushNotificationLogEvent { } if (has_photo) { td::parse(photo_, parser); - } else { - photo_.id = -2; } if (has_document) { td::parse(document_, parser); diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index 96b340ea7..c78fa4f39 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -575,6 +575,7 @@ Photo get_encrypted_file_photo(FileManager *file_manager, tl_object_ptrset_encryption_key(file_id, FileEncryptionKey{photo->key_.as_slice(), photo->iv_.as_slice()}); Photo res; + res.id = 0; res.date = 0; if (!photo->thumb_.empty()) { @@ -594,9 +595,7 @@ Photo get_encrypted_file_photo(FileManager *file_manager, tl_object_ptr &&photo, DialogId owner_dialog_id) { if (photo == nullptr || photo->get_id() == telegram_api::photoEmpty::ID) { - Photo result; - result.id = -2; - return result; + return Photo(); } CHECK(photo->get_id() == telegram_api::photo::ID); return get_photo(file_manager, move_tl_object_as(photo), owner_dialog_id); @@ -638,9 +637,7 @@ Photo get_web_document_photo(FileManager *file_manager, tl_object_ptr photos; diff --git a/td/telegram/WebPageBlock.cpp b/td/telegram/WebPageBlock.cpp index b8b9a3ae1..aff622b9a 100644 --- a/td/telegram/WebPageBlock.cpp +++ b/td/telegram/WebPageBlock.cpp @@ -423,8 +423,6 @@ class RelatedArticle { } if (has_photo) { parse(photo, parser); - } else { - photo.id = -2; } if (has_author) { parse(author, parser); @@ -2019,9 +2017,7 @@ unique_ptr get_web_page_block(Td *td, tl_object_ptr(page_block_ptr); auto it = photos.find(page_block->photo_id_); Photo photo; - if (it == photos.end()) { - photo.id = -2; - } else { + if (it != photos.end()) { photo = it->second; } string url; @@ -2071,9 +2067,7 @@ unique_ptr get_web_page_block(Td *td, tl_object_ptrposter_photo_id_) : photos.end(); Photo poster_photo; - if (it == photos.end()) { - poster_photo.id = -2; - } else { + if (it != photos.end()) { poster_photo = it->second; } Dimensions dimensions; @@ -2088,9 +2082,7 @@ unique_ptr get_web_page_block(Td *td, tl_object_ptr(page_block_ptr); auto it = photos.find(page_block->author_photo_id_); Photo author_photo; - if (it == photos.end()) { - author_photo.id = -2; - } else { + if (it != photos.end()) { author_photo = it->second; } return td::make_unique( @@ -2215,9 +2207,7 @@ unique_ptr get_web_page_block(Td *td, tl_object_ptrflags_ & telegram_api::pageRelatedArticle::PHOTO_ID_MASK) != 0 ? photos.find(related_article->photo_id_) : photos.end(); - if (it == photos.end()) { - article.photo.id = -2; - } else { + if (it != photos.end()) { article.photo = it->second; } article.author = std::move(related_article->author_); diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index c1a1da24e..e5301763f 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -358,8 +358,6 @@ class WebPagesManager::WebPage { } if (has_photo) { parse(photo, parser); - } else { - photo.id = -2; } if (has_embed) { parse(embed_url, parser);