From 113f3a70803e3d7c9d1d1d1ab180af0af64d6f7a Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 1 Jun 2020 20:34:48 +0300 Subject: [PATCH] Add thumbnailFormatGif. GitOrigin-RevId: 4ad35c83a6ae47d92cbb66cb60622d147f11c7b4 --- td/generate/scheme/td_api.tl | 3 +++ td/generate/scheme/td_api.tlo | Bin 174420 -> 174480 bytes td/telegram/DocumentsManager.cpp | 3 +++ td/telegram/InlineQueriesManager.cpp | 7 ++++--- td/telegram/Photo.cpp | 13 +++++++++++-- td/telegram/Photo.h | 2 +- 6 files changed, 22 insertions(+), 6 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 2ea4d942b..d7001e7ee 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -196,6 +196,9 @@ thumbnailFormatPng = ThumbnailFormat; //@description The thumbnail is in WEBP format. It will be used only for some stickers thumbnailFormatWebp = ThumbnailFormat; +//@description The thumbnail is in static GIF format. It will be used only for some bot inline results +thumbnailFormatGif = ThumbnailFormat; + //@description The thumbnail is in TGS format. It will be used only for animated sticker sets thumbnailFormatTgs = ThumbnailFormat; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index c7c2bee8fd28ddaf739221bef098751195a4a0b9..31969161143d072a73a362fb0c7c83f61aaa1013 100644 GIT binary patch delta 286 zcmca|iEF}Tt_=lRqMlo)=JSVSl;$SoC1&QhmD+Pu7_tGCgMrqm2Ye?B+2c9|j;Oa%R)vux&dC5}STt38M;b**`$p z5L|jeW`V#}Ij)#4)x};yC8(}*&rD;$rFXi;QhfH7EM?Td>8kcEOBuIsS<1A482~MK BWYhov delta 226 zcmbPmnd{0Wt_=lRqK7A#sq%+pl;$SoC1&Qh InlineQueriesManager::register_thumbnail( return nullptr; } - return get_thumbnail_object(td_->file_manager_.get(), thumbnail, PhotoFormat::Jpeg); + return get_thumbnail_object(td_->file_manager_.get(), thumbnail, + thumbnail.type == 'g' ? PhotoFormat::Gif : PhotoFormat::Jpeg); } string InlineQueriesManager::get_web_document_url(const tl_object_ptr &web_document_ptr) { @@ -1414,7 +1415,7 @@ void InlineQueriesManager::on_get_inline_query_results(UserId bot_user_id, uint6 PhotoSize photo_size = get_web_document_photo_size(td_->file_manager_.get(), FileType::Temp, DialogId(), std::move(result->content_)); - if (!photo_size.file_id.is_valid() || photo_size.type == 'v') { + if (!photo_size.file_id.is_valid() || photo_size.type == 'v' || photo_size.type == 'g') { LOG(ERROR) << "Receive invalid web document photo"; continue; } @@ -1422,7 +1423,7 @@ void InlineQueriesManager::on_get_inline_query_results(UserId bot_user_id, uint6 Photo new_photo; 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') { + if (thumbnail.file_id.is_valid() && thumbnail.type != 'v' && thumbnail.type != 'g') { new_photo.photos.push_back(std::move(thumbnail)); } new_photo.photos.push_back(std::move(photo_size)); diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index e0cec4c84..84a7da60a 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -103,6 +103,8 @@ static td_api::object_ptr get_thumbnail_format_object(P return td_api::make_object(); case PhotoFormat::Webp: return td_api::make_object(); + case PhotoFormat::Gif: + return td_api::make_object(); case PhotoFormat::Tgs: return td_api::make_object(); case PhotoFormat::Mpeg4: @@ -121,6 +123,8 @@ static StringBuilder &operator<<(StringBuilder &string_builder, PhotoFormat form return string_builder << "png"; case PhotoFormat::Webp: return string_builder << "webp"; + case PhotoFormat::Gif: + return string_builder << "gif"; case PhotoFormat::Tgs: return string_builder << "tgs"; case PhotoFormat::Mpeg4: @@ -455,6 +459,7 @@ PhotoSize get_web_document_photo_size(FileManager *file_manager, FileType file_t } CHECK(file_id.is_valid()); bool is_animation = mime_type == "video/mp4"; + bool is_gif = mime_type == "image/gif"; Dimensions dimensions; for (auto &attribute : attributes) { @@ -479,7 +484,7 @@ PhotoSize get_web_document_photo_size(FileManager *file_manager, FileType file_t } PhotoSize s; - s.type = is_animation ? 'v' : (file_type == FileType::Thumbnail ? 't' : 'u'); + s.type = is_animation ? 'v' : (is_gif ? 'g' : (file_type == FileType::Thumbnail ? 't' : 'u')); s.dimensions = dimensions; s.size = size; s.file_id = file_id; @@ -492,6 +497,10 @@ td_api::object_ptr get_thumbnail_object(FileManager *file_man return nullptr; } + if (format == PhotoFormat::Jpeg && photo_size.type == 'g') { + format = PhotoFormat::Gif; + } + return td_api::make_object(get_thumbnail_format_object(format), photo_size.dimensions.width, photo_size.dimensions.height, file_manager->get_file_object(photo_size.file_id)); @@ -628,7 +637,7 @@ Photo get_web_document_photo(FileManager *file_manager, tl_object_ptr