From 004e1dcc8dd1ed2304495e956589595f2037feb6 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 24 Jun 2020 14:13:33 +0300 Subject: [PATCH] Add userProfilePhoto.animation. GitOrigin-RevId: 69760b287f8c9bd304db7789e503dda478cf9c59 --- td/generate/scheme/td_api.tl | 8 +++++-- td/generate/scheme/td_api.tlo | Bin 174728 -> 174764 bytes td/telegram/MessageContent.cpp | 2 +- td/telegram/Photo.cpp | 41 +++++++++++++++++++++++++-------- td/telegram/Photo.h | 2 ++ td/telegram/Photo.hpp | 10 ++++++++ 6 files changed, 50 insertions(+), 13 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index ec7a2e28a..15dafeab1 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -344,8 +344,12 @@ botInfo description:string commands:vector = BotInfo; chatLocation location:location address:string = ChatLocation; -//@description Describes a chat or user profile photo @id Unique photo identifier @added_date Point in time (Unix timestamp) when the photo has been added @sizes Available variants of the photo, in different size -chatPhoto id:int64 added_date:int32 sizes:vector = ChatPhoto; +//@description Describes a chat or user profile photo +//@id Unique photo identifier +//@added_date Point in time (Unix timestamp) when the photo has been added +//@sizes Available variants of the photo in JPEG format, in different size +//@animation Animated variant of the photo in MPEG4 format; may be null +chatPhoto id:int64 added_date:int32 sizes:vector animation:photoSize = ChatPhoto; //@description Contains a list of chat or user profile photos @total_count Total number of photos @photos List of photos chatPhotos total_count:int32 photos:vector = ChatPhotos; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 173d23a696e2797478bc61a4956e9a7a0131b9aa..ef19d8de7eae6342087d075cc1dbe63b520adf1b 100644 GIT binary patch delta 154 zcmeCU%C+Vy*M=#aEcwCKW}9bl)>wd9lLZzUZ1!-&kH0V(H9 z&PXf?$jC3rXJ7#FCo8Oym@Hr;IJveuc(TSCiOEN*MIid`RKEZ-rZ ZZa3g$eA5PDDokK(@rE#0+-7`m4gjaGI3fT5 delta 163 zcmZ2;m8;__*M=#aEK6HCr8m#utg!&IrU#fY8f^A(%25DwC+|ptG7cmvZvLC(EFl6? z&zYQ&SQ3ztUy{$j0OC)75XPu6xu!aVr^uO2hr_n*AV_pl%?pU>Z)#F{AjWO@r?9<* hlkrR&!m`OZ=^T>{92K_DnZT&y4Hn;i<~HMla{$$_JTm|Q diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 2e1718b0a..0b081dc32 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -1684,7 +1684,7 @@ static Result create_input_message_content( auto invoice_file_id = r_invoice_file_id.move_as_ok(); PhotoSize s; - s.type = 'u'; + s.type = 'n'; s.dimensions = get_dimensions(input_invoice->photo_width_, input_invoice->photo_height_); s.size = input_invoice->photo_size_; // TODO use invoice_file_id size s.file_id = invoice_file_id; diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index c362536a7..d5b428dc0 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -279,6 +279,7 @@ DialogPhoto as_dialog_photo(const Photo &photo) { result.big_file_id = size.file_id; } } + result.is_animated = !photo.animated_photos.empty(); if (!result.small_file_id.is_valid() || !result.big_file_id.is_valid()) { LOG(ERROR) << "Failed to convert " << photo << " to chat photo"; return DialogPhoto(); @@ -397,10 +398,10 @@ PhotoSize get_video_photo_size(FileManager *file_manager, PhotoSizeSource source tl_object_ptr &&size) { CHECK(size != nullptr); PhotoSize res; - if (size->type_ != "v") { + if (size->type_ != "v" && size->type_ != "u") { LOG(ERROR) << "Wrong videoSize \"" << size->type_ << "\" in " << to_string(size); } - res.type = static_cast('v'); + res.type = static_cast(size->type_[0]); res.dimensions = get_dimensions(size->w_, size->h_); res.size = size->size_; @@ -490,7 +491,7 @@ PhotoSize get_web_document_photo_size(FileManager *file_manager, FileType file_t } PhotoSize s; - s.type = is_animation ? 'v' : (is_gif ? 'g' : (file_type == FileType::Thumbnail ? 't' : 'u')); + s.type = is_animation ? 'v' : (is_gif ? 'g' : (file_type == FileType::Thumbnail ? 't' : 'n')); s.dimensions = dimensions; s.size = size; s.file_id = file_id; @@ -620,13 +621,14 @@ Photo get_photo(FileManager *file_manager, tl_object_ptr && res.id = -3; } + DcId dc_id = DcId::create(photo->dc_id_); 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_), - owner_dialog_id, std::move(size_ptr), PhotoFormat::Jpeg); + photo->file_reference_.as_slice().str(), dc_id, owner_dialog_id, + std::move(size_ptr), PhotoFormat::Jpeg); if (photo_size.get_offset() == 0) { PhotoSize &size = photo_size.get<0>(); - if (size.type == 0 || size.type == 't' || size.type == 'i') { + if (size.type == 0 || size.type == 't' || size.type == 'i' || size.type == 'u' || size.type == 'v') { LOG(ERROR) << "Skip unallowed photo size " << size; continue; } @@ -636,6 +638,12 @@ Photo get_photo(FileManager *file_manager, tl_object_ptr && } } + for (auto &size_ptr : photo->video_sizes_) { + res.animated_photos.push_back(get_video_photo_size(file_manager, {FileType::Photo, 0}, photo->id_, + photo->access_hash_, photo->file_reference_.as_slice().str(), + dc_id, owner_dialog_id, std::move(size_ptr))); + } + return res; } @@ -664,8 +672,10 @@ tl_object_ptr get_chat_photo_object(FileManager *file_manager return nullptr; } + const PhotoSize *animation = photo.animated_photos.empty() ? nullptr : &photo.animated_photos.back(); return td_api::make_object(photo.id.get(), photo.date, - get_photo_sizes_object(file_manager, photo.photos)); + get_photo_sizes_object(file_manager, photo.photos), + get_photo_size_object(file_manager, animation)); } void photo_delete_thumbnail(Photo &photo) { @@ -803,11 +813,15 @@ SecretInputMedia photo_get_secret_input_media(FileManager *file_manager, const P } vector photo_get_file_ids(const Photo &photo) { - return transform(photo.photos, [](auto &size) { return size.file_id; }); + auto result = transform(photo.photos, [](auto &size) { return size.file_id; }); + if (!photo.animated_photos.empty()) { + append(result, transform(photo.animated_photos, [](auto &size) { return size.file_id; })); + } + return result; } bool operator==(const Photo &lhs, const Photo &rhs) { - return lhs.id.get() == rhs.id.get() && lhs.photos == rhs.photos; + return lhs.id.get() == rhs.id.get() && lhs.photos == rhs.photos && lhs.animated_photos == rhs.animated_photos; } bool operator!=(const Photo &lhs, const Photo &rhs) { @@ -815,7 +829,11 @@ bool operator!=(const Photo &lhs, const Photo &rhs) { } StringBuilder &operator<<(StringBuilder &string_builder, const Photo &photo) { - return string_builder << "[id = " << photo.id.get() << ", photos = " << format::as_array(photo.photos) << "]"; + string_builder << "[id = " << photo.id.get() << ", photos = " << format::as_array(photo.photos); + if (!photo.animated_photos.empty()) { + string_builder << ", animated photos = " << format::as_array(photo.animated_photos); + } + return string_builder << "]"; } static tl_object_ptr copy_location( @@ -865,6 +883,9 @@ tl_object_ptr convert_photo_to_profile_photo( return nullptr; } int32 flags = 0; + if (!photo->video_sizes_.empty()) { + flags |= telegram_api::userProfilePhoto::HAS_VIDEO_MASK; + } return make_tl_object(flags, false /*ignored*/, photo->id_, std::move(photo_small), std::move(photo_big), photo->dc_id_); } diff --git a/td/telegram/Photo.h b/td/telegram/Photo.h index 0eb0c33ad..4990d0327 100644 --- a/td/telegram/Photo.h +++ b/td/telegram/Photo.h @@ -56,6 +56,8 @@ struct Photo { string minithumbnail; vector photos; + vector animated_photos; + bool has_stickers = false; vector sticker_file_ids; diff --git a/td/telegram/Photo.hpp b/td/telegram/Photo.hpp index 63765aeb2..b868a414d 100644 --- a/td/telegram/Photo.hpp +++ b/td/telegram/Photo.hpp @@ -73,9 +73,11 @@ void parse(PhotoSize &photo_size, ParserT &parser) { template void store(const Photo &photo, StorerT &storer) { bool has_minithumbnail = !photo.minithumbnail.empty(); + bool has_animated_photos = !photo.animated_photos.empty(); BEGIN_STORE_FLAGS(); STORE_FLAG(photo.has_stickers); STORE_FLAG(has_minithumbnail); + STORE_FLAG(has_animated_photos); END_STORE_FLAGS(); store(photo.id.get(), storer); store(photo.date, storer); @@ -86,14 +88,19 @@ void store(const Photo &photo, StorerT &storer) { if (has_minithumbnail) { store(photo.minithumbnail, storer); } + if (has_animated_photos) { + store(photo.animated_photos, storer); + } } template void parse(Photo &photo, ParserT &parser) { bool has_minithumbnail; + bool has_animated_photos; BEGIN_PARSE_FLAGS(); PARSE_FLAG(photo.has_stickers); PARSE_FLAG(has_minithumbnail); + PARSE_FLAG(has_animated_photos); END_PARSE_FLAGS(); int64 id; parse(id, parser); @@ -106,6 +113,9 @@ void parse(Photo &photo, ParserT &parser) { if (has_minithumbnail) { parse(photo.minithumbnail, parser); } + if (has_animated_photos) { + parse(photo.animated_photos, parser); + } } } // namespace td