Init photo ID to invalid by default.
GitOrigin-RevId: 072cd8bbd87267e086ed9a280ba5238e5e231a84
This commit is contained in:
parent
b02b578ab9
commit
ef04c17a89
@ -3241,6 +3241,7 @@ template <class StorerT>
|
||||
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 <class ParserT>
|
||||
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 <class StorerT>
|
||||
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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') {
|
||||
|
@ -1529,6 +1529,8 @@ static Result<InputMessageContent> 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<InputMessageContent> 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<InputMessageContent> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -575,6 +575,7 @@ Photo get_encrypted_file_photo(FileManager *file_manager, tl_object_ptr<telegram
|
||||
file_manager->set_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<telegram
|
||||
|
||||
Photo get_photo(FileManager *file_manager, tl_object_ptr<telegram_api::Photo> &&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<telegram_api::photo>(photo), owner_dialog_id);
|
||||
@ -638,9 +637,7 @@ Photo get_web_document_photo(FileManager *file_manager, tl_object_ptr<telegram_a
|
||||
DialogId owner_dialog_id) {
|
||||
PhotoSize s = get_web_document_photo_size(file_manager, FileType::Photo, owner_dialog_id, std::move(web_document));
|
||||
Photo photo;
|
||||
if (!s.file_id.is_valid() || s.type == 'v' || s.type == 'g') {
|
||||
photo.id = -2;
|
||||
} else {
|
||||
if (s.file_id.is_valid() && s.type != 'v' && s.type != 'g') {
|
||||
photo.id = 0;
|
||||
photo.photos.push_back(s);
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ struct PhotoSize {
|
||||
};
|
||||
|
||||
struct Photo {
|
||||
int64 id = 0;
|
||||
int64 id = -2;
|
||||
int32 date = 0;
|
||||
string minithumbnail;
|
||||
vector<PhotoSize> photos;
|
||||
|
@ -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<WebPageBlock> get_web_page_block(Td *td, tl_object_ptr<telegram_api::
|
||||
auto page_block = move_tl_object_as<telegram_api::pageBlockPhoto>(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<WebPageBlock> get_web_page_block(Td *td, tl_object_ptr<telegram_api::
|
||||
? photos.find(page_block->poster_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<WebPageBlock> get_web_page_block(Td *td, tl_object_ptr<telegram_api::
|
||||
auto page_block = move_tl_object_as<telegram_api::pageBlockEmbedPost>(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<WebPageBlockEmbeddedPost>(
|
||||
@ -2215,9 +2207,7 @@ unique_ptr<WebPageBlock> get_web_page_block(Td *td, tl_object_ptr<telegram_api::
|
||||
auto it = (related_article->flags_ & 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_);
|
||||
|
@ -358,8 +358,6 @@ class WebPagesManager::WebPage {
|
||||
}
|
||||
if (has_photo) {
|
||||
parse(photo, parser);
|
||||
} else {
|
||||
photo.id = -2;
|
||||
}
|
||||
if (has_embed) {
|
||||
parse(embed_url, parser);
|
||||
|
Loading…
Reference in New Issue
Block a user