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 c7c2bee8f..319691611 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/DocumentsManager.cpp b/td/telegram/DocumentsManager.cpp index 2a6031fc4..0c632cfcd 100644 --- a/td/telegram/DocumentsManager.cpp +++ b/td/telegram/DocumentsManager.cpp @@ -313,6 +313,9 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo animated_thumbnail = std::move(remote_document.thumbnail); } else { thumbnail = std::move(remote_document.thumbnail); + if (remote_document.thumbnail.type == 'g') { + thumbnail_format = PhotoFormat::Gif; + } } auto web_document_ptr = std::move(remote_document.web_document); diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index 1ce3358a6..d8ef081dc 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -1092,7 +1092,8 @@ tl_object_ptr 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