Add thumbnailFormatGif.

GitOrigin-RevId: 4ad35c83a6ae47d92cbb66cb60622d147f11c7b4
This commit is contained in:
levlam 2020-06-01 20:34:48 +03:00
parent 01b319f22b
commit 113f3a7080
6 changed files with 22 additions and 6 deletions

View File

@ -196,6 +196,9 @@ thumbnailFormatPng = ThumbnailFormat;
//@description The thumbnail is in WEBP format. It will be used only for some stickers //@description The thumbnail is in WEBP format. It will be used only for some stickers
thumbnailFormatWebp = ThumbnailFormat; 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 //@description The thumbnail is in TGS format. It will be used only for animated sticker sets
thumbnailFormatTgs = ThumbnailFormat; thumbnailFormatTgs = ThumbnailFormat;

Binary file not shown.

View File

@ -313,6 +313,9 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
animated_thumbnail = std::move(remote_document.thumbnail); animated_thumbnail = std::move(remote_document.thumbnail);
} else { } else {
thumbnail = std::move(remote_document.thumbnail); 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); auto web_document_ptr = std::move(remote_document.web_document);

View File

@ -1092,7 +1092,8 @@ tl_object_ptr<td_api::thumbnail> InlineQueriesManager::register_thumbnail(
return nullptr; 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<telegram_api::WebDocument> &web_document_ptr) { string InlineQueriesManager::get_web_document_url(const tl_object_ptr<telegram_api::WebDocument> &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(), PhotoSize photo_size = get_web_document_photo_size(td_->file_manager_.get(), FileType::Temp, DialogId(),
std::move(result->content_)); 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"; LOG(ERROR) << "Receive invalid web document photo";
continue; continue;
} }
@ -1422,7 +1423,7 @@ void InlineQueriesManager::on_get_inline_query_results(UserId bot_user_id, uint6
Photo new_photo; Photo new_photo;
PhotoSize thumbnail = get_web_document_photo_size(td_->file_manager_.get(), FileType::Thumbnail, DialogId(), PhotoSize thumbnail = get_web_document_photo_size(td_->file_manager_.get(), FileType::Thumbnail, DialogId(),
std::move(result->thumb_)); 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(thumbnail));
} }
new_photo.photos.push_back(std::move(photo_size)); new_photo.photos.push_back(std::move(photo_size));

View File

@ -103,6 +103,8 @@ static td_api::object_ptr<td_api::ThumbnailFormat> get_thumbnail_format_object(P
return td_api::make_object<td_api::thumbnailFormatPng>(); return td_api::make_object<td_api::thumbnailFormatPng>();
case PhotoFormat::Webp: case PhotoFormat::Webp:
return td_api::make_object<td_api::thumbnailFormatWebp>(); return td_api::make_object<td_api::thumbnailFormatWebp>();
case PhotoFormat::Gif:
return td_api::make_object<td_api::thumbnailFormatGif>();
case PhotoFormat::Tgs: case PhotoFormat::Tgs:
return td_api::make_object<td_api::thumbnailFormatTgs>(); return td_api::make_object<td_api::thumbnailFormatTgs>();
case PhotoFormat::Mpeg4: case PhotoFormat::Mpeg4:
@ -121,6 +123,8 @@ static StringBuilder &operator<<(StringBuilder &string_builder, PhotoFormat form
return string_builder << "png"; return string_builder << "png";
case PhotoFormat::Webp: case PhotoFormat::Webp:
return string_builder << "webp"; return string_builder << "webp";
case PhotoFormat::Gif:
return string_builder << "gif";
case PhotoFormat::Tgs: case PhotoFormat::Tgs:
return string_builder << "tgs"; return string_builder << "tgs";
case PhotoFormat::Mpeg4: case PhotoFormat::Mpeg4:
@ -455,6 +459,7 @@ PhotoSize get_web_document_photo_size(FileManager *file_manager, FileType file_t
} }
CHECK(file_id.is_valid()); CHECK(file_id.is_valid());
bool is_animation = mime_type == "video/mp4"; bool is_animation = mime_type == "video/mp4";
bool is_gif = mime_type == "image/gif";
Dimensions dimensions; Dimensions dimensions;
for (auto &attribute : attributes) { for (auto &attribute : attributes) {
@ -479,7 +484,7 @@ PhotoSize get_web_document_photo_size(FileManager *file_manager, FileType file_t
} }
PhotoSize s; 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.dimensions = dimensions;
s.size = size; s.size = size;
s.file_id = file_id; s.file_id = file_id;
@ -492,6 +497,10 @@ td_api::object_ptr<td_api::thumbnail> get_thumbnail_object(FileManager *file_man
return nullptr; return nullptr;
} }
if (format == PhotoFormat::Jpeg && photo_size.type == 'g') {
format = PhotoFormat::Gif;
}
return td_api::make_object<td_api::thumbnail>(get_thumbnail_format_object(format), photo_size.dimensions.width, return td_api::make_object<td_api::thumbnail>(get_thumbnail_format_object(format), photo_size.dimensions.width,
photo_size.dimensions.height, photo_size.dimensions.height,
file_manager->get_file_object(photo_size.file_id)); file_manager->get_file_object(photo_size.file_id));
@ -628,7 +637,7 @@ Photo get_web_document_photo(FileManager *file_manager, tl_object_ptr<telegram_a
DialogId owner_dialog_id) { DialogId owner_dialog_id) {
PhotoSize s = get_web_document_photo_size(file_manager, FileType::Photo, owner_dialog_id, std::move(web_document)); PhotoSize s = get_web_document_photo_size(file_manager, FileType::Photo, owner_dialog_id, std::move(web_document));
Photo photo; Photo photo;
if (!s.file_id.is_valid() || s.type == 'v') { if (!s.file_id.is_valid() || s.type == 'v' || s.type == 'g') {
photo.id = -2; photo.id = -2;
} else { } else {
photo.id = 0; photo.id = 0;

View File

@ -90,7 +90,7 @@ bool operator!=(const DialogPhoto &lhs, const DialogPhoto &rhs);
StringBuilder &operator<<(StringBuilder &string_builder, const DialogPhoto &dialog_photo); StringBuilder &operator<<(StringBuilder &string_builder, const DialogPhoto &dialog_photo);
enum class PhotoFormat : int32 { Jpeg, Png, Webp, Tgs, Mpeg4 }; enum class PhotoFormat : int32 { Jpeg, Png, Webp, Gif, Tgs, Mpeg4 };
PhotoSize get_secret_thumbnail_photo_size(FileManager *file_manager, BufferSlice bytes, DialogId owner_dialog_id, PhotoSize get_secret_thumbnail_photo_size(FileManager *file_manager, BufferSlice bytes, DialogId owner_dialog_id,
int32 width, int32 height); int32 width, int32 height);