From 4acf82c506a43fa81e5d24ed3d23b85ea89247f6 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 23 Jun 2020 21:04:26 +0300 Subject: [PATCH] Add Photo.is_empty(). GitOrigin-RevId: 6dd6aeaaaa703f9cd865598d52b97eb64523fea0 --- td/telegram/ContactsManager.cpp | 8 ++++---- td/telegram/Game.cpp | 2 +- td/telegram/InlineQueriesManager.cpp | 2 +- td/telegram/MessageContent.cpp | 6 +++--- td/telegram/NotificationManager.cpp | 4 ++-- td/telegram/Photo.cpp | 8 ++++---- td/telegram/Photo.h | 4 ++++ td/telegram/WebPageBlock.cpp | 4 ++-- td/telegram/WebPagesManager.cpp | 6 +++--- 9 files changed, 24 insertions(+), 20 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 390cb7c2b..f67ff4235 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -3241,7 +3241,7 @@ template void ContactsManager::UserFull::store(StorerT &storer) const { using td::store; bool has_about = !about.empty(); - bool has_photo = photo.id != -2; + bool has_photo = !photo.is_empty(); BEGIN_STORE_FLAGS(); STORE_FLAG(has_about); STORE_FLAG(is_blocked); @@ -8911,7 +8911,7 @@ void ContactsManager::on_get_user_full(tl_object_ptr &&u } user->photo = get_photo(td_->file_manager_.get(), std::move(user_full->profile_photo_), DialogId()); - if (user->photo.id == -2) { + if (user->photo.is_empty()) { drop_user_photos(user_id, true, false, "on_get_user_full"); } else { add_user_photo_id(u, user_id, user->photo.id, photo_get_file_ids(user->photo)); @@ -8990,7 +8990,7 @@ void ContactsManager::on_get_user_photos(UserId user_id, int32 offset, int32 lim for (auto &photo : photos) { auto user_photo = get_photo(td_->file_manager_.get(), std::move(photo), DialogId()); - if (user_photo.id == -2) { + if (user_photo.is_empty()) { LOG(ERROR) << "Receive empty profile photo in getUserPhotos request for " << user_id << " with offset " << offset << " and limit " << limit << ". Receive " << photo_count << " photos out of " << total_count << " photos"; @@ -9750,7 +9750,7 @@ void ContactsManager::drop_user_photos(UserId user_id, bool is_empty, bool drop_ } if (is_empty) { - if (user_full->photo.id != -2) { + if (!user_full->photo.is_empty()) { user_full->photo = Photo(); user_full->is_changed = true; } diff --git a/td/telegram/Game.cpp b/td/telegram/Game.cpp index c6ceac21e..c4eea22c4 100644 --- a/td/telegram/Game.cpp +++ b/td/telegram/Game.cpp @@ -36,7 +36,7 @@ Game::Game(Td *td, string title, string description, tl_object_ptrfile_manager_.get(), std::move(photo), owner_dialog_id); - if (photo_.id == -2) { + if (photo_.is_empty()) { LOG(ERROR) << "Receive empty photo for game " << title; photo_.id = 0; // to prevent null photo in td_api } diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index 2a0be4674..f12af83c5 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -1300,7 +1300,7 @@ void InlineQueriesManager::on_get_inline_query_results(UserId bot_user_id, uint6 auto photo = make_tl_object(); photo->id_ = std::move(result->id_); Photo p = get_photo(td_->file_manager_.get(), std::move(result->photo_), DialogId()); - if (p.id == -2) { + if (p.is_empty()) { LOG(ERROR) << "Receive empty cached photo in the result of inline query"; break; } diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 549692bf5..7a35bd785 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -2129,7 +2129,7 @@ static tl_object_ptr get_input_invoice(const Invoice &inv static tl_object_ptr get_input_web_document(const FileManager *file_manager, const Photo &photo) { - if (photo.id == -2) { + if (photo.is_empty()) { return nullptr; } @@ -3785,7 +3785,7 @@ unique_ptr get_message_content(Td *td, FormattedText message, } auto photo = get_photo(td->file_manager_.get(), std::move(message_photo->photo_), owner_dialog_id); - if (photo.id == -2) { + if (photo.is_empty()) { return make_unique(); } @@ -4197,7 +4197,7 @@ unique_ptr get_action_message_content(Td *td, tl_object_ptr(action); auto photo = get_photo(td->file_manager_.get(), std::move(chat_edit_photo->photo_), owner_dialog_id); - if (photo.id == -2) { + if (photo.is_empty()) { break; } return make_unique(std::move(photo)); diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index 44eabee94..0edb4559e 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -3425,7 +3425,7 @@ class NotificationManager::AddMessagePushNotificationLogEvent { bool has_sender = sender_user_id_.is_valid(); bool has_sender_name = !sender_name_.empty(); bool has_arg = !arg_.empty(); - bool has_photo = photo_.id != -2; + bool has_photo = !photo_.is_empty(); bool has_document = !document_.empty(); BEGIN_STORE_FLAGS(); STORE_FLAG(contains_mention_); @@ -3630,7 +3630,7 @@ class NotificationManager::EditMessagePushNotificationLogEvent { void store(StorerT &storer) const { bool has_message_id = message_id_.is_valid(); bool has_arg = !arg_.empty(); - bool has_photo = photo_.id != -2; + bool has_photo = !photo_.is_empty(); bool has_document = !document_.empty(); BEGIN_STORE_FLAGS(); STORE_FLAG(has_message_id); diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index c78fa4f39..3dbd428fc 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -267,7 +267,7 @@ vector dialog_photo_get_file_ids(const DialogPhoto &dialog_photo) { DialogPhoto as_dialog_photo(const Photo &photo) { DialogPhoto result; - if (photo.id != -2) { + if (!photo.is_empty()) { for (auto &size : photo.photos) { if (size.type == 'a') { result.small_file_id = size.file_id; @@ -609,7 +609,7 @@ 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) { + if (res.is_empty()) { LOG(ERROR) << "Receive photo with id " << res.id; res.id = -3; } @@ -645,7 +645,7 @@ Photo get_web_document_photo(FileManager *file_manager, tl_object_ptr get_photo_object(FileManager *file_manager, const Photo *photo) { - if (photo == nullptr || photo->id == -2) { + if (photo == nullptr || photo->is_empty()) { return nullptr; } @@ -654,7 +654,7 @@ tl_object_ptr get_photo_object(FileManager *file_manager, const P } tl_object_ptr get_user_profile_photo_object(FileManager *file_manager, const Photo *photo) { - if (photo == nullptr || photo->id == -2) { + if (photo == nullptr || photo->is_empty()) { return nullptr; } diff --git a/td/telegram/Photo.h b/td/telegram/Photo.h index f02eeb6d7..fd49be62a 100644 --- a/td/telegram/Photo.h +++ b/td/telegram/Photo.h @@ -56,6 +56,10 @@ struct Photo { bool has_stickers = false; vector sticker_file_ids; + + bool is_empty() const { + return id == -2; + } }; Dimensions get_dimensions(int32 width, int32 height); diff --git a/td/telegram/WebPageBlock.cpp b/td/telegram/WebPageBlock.cpp index aff622b9a..ca5746698 100644 --- a/td/telegram/WebPageBlock.cpp +++ b/td/telegram/WebPageBlock.cpp @@ -369,7 +369,7 @@ class RelatedArticle { using ::td::store; bool has_title = !title.empty(); bool has_description = !description.empty(); - bool has_photo = photo.id != -2; + bool has_photo = !photo.is_empty(); bool has_author = !author.empty(); bool has_date = published_date != 0; BEGIN_STORE_FLAGS(); @@ -1622,7 +1622,7 @@ class WebPageBlockRelatedArticles : public WebPageBlock { void append_file_ids(const Td *td, vector &file_ids) const override { header.append_file_ids(td, file_ids); for (auto &article : related_articles) { - if (article.photo.id != -2) { + if (!article.photo.is_empty()) { append(file_ids, photo_get_file_ids(article.photo)); } } diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index e5301763f..bab833998 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -239,7 +239,7 @@ class WebPagesManager::WebPage { bool has_site_name = !site_name.empty(); bool has_title = !title.empty(); bool has_description = !description.empty(); - bool has_photo = photo.id != -2; + bool has_photo = !photo.is_empty(); bool has_embed = !embed_url.empty(); bool has_embed_dimensions = has_embed && embed_dimensions != Dimensions(); bool has_duration = duration > 0; @@ -1391,14 +1391,14 @@ void WebPagesManager::on_get_web_page_instant_view(WebPage *web_page, tl_object_ std::unordered_map photos; for (auto &photo_ptr : page->photos_) { Photo photo = get_photo(td_->file_manager_.get(), std::move(photo_ptr), owner_dialog_id); - if (photo.id == -2 || photo.id == 0) { + if (photo.is_empty() || photo.id == 0) { LOG(ERROR) << "Receive empty photo in web page instant view for " << web_page->url; } else { auto photo_id = photo.id; photos.emplace(photo_id, std::move(photo)); } } - if (web_page->photo.id != -2 && web_page->photo.id != 0) { + if (!web_page->photo.is_empty() && web_page->photo.id != 0) { photos.emplace(web_page->photo.id, web_page->photo); }