diff --git a/td/telegram/DocumentsManager.cpp b/td/telegram/DocumentsManager.cpp index c5c12acdc..c396d1f2c 100644 --- a/td/telegram/DocumentsManager.cpp +++ b/td/telegram/DocumentsManager.cpp @@ -167,9 +167,6 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo default_extension = Slice("webp"); owner_dialog_id = DialogId(); file_name.clear(); - if (td_->stickers_manager_->has_webp_thumbnail(sticker) && remote_document.secret_file == nullptr) { - thumbnail_format = PhotoFormat::Webp; - } } else if (video != nullptr || default_document_type == Document::Type::Video || default_document_type == Document::Type::VideoNote) { bool is_video_note = default_document_type == Document::Type::VideoNote; @@ -252,6 +249,9 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo mime_type = std::move(document->mime_type_); file_reference = document->file_reference_.as_slice().str(); + if (document_type == Document::Type::Sticker && StickersManager::has_webp_thumbnail(document->thumbs_)) { + thumbnail_format = PhotoFormat::Webp; + } fix_animated_sticker_type(); if (owner_dialog_id.get_type() == DialogType::SecretChat) { diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 4b36e7033..2bb94dc10 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -1830,8 +1830,19 @@ FileId StickersManager::on_get_sticker(unique_ptr new_sticker, bool rep return file_id; } -bool StickersManager::has_webp_thumbnail(const tl_object_ptr &sticker) { - // server tries to always replace user-provided thumbnail with server-side webp thumbnail +bool StickersManager::has_webp_thumbnail(const vector> &thumbnails) { + // server tries to always replace user-provided thumbnail with server-side WEBP thumbnail + // but there can be some old sticker documents or some big stickers + for (auto &size : thumbnails) { + switch (size->get_id()) { + case telegram_api::photoStrippedSize::ID: + case telegram_api::photoSizeProgressive::ID: + // WEBP thumbnail can't have stripped size or be progressive + return false; + default: + break; + } + } return true; } @@ -1884,11 +1895,11 @@ std::pair StickersManager::on_get_sticker_document( PhotoSize thumbnail; string minithumbnail; + auto thumbnail_format = has_webp_thumbnail(document->thumbs_) ? PhotoFormat::Webp : PhotoFormat::Jpeg; for (auto &thumb : document->thumbs_) { - auto photo_size = - get_photo_size(td_->file_manager_.get(), {FileType::Thumbnail, 0}, document_id, document->access_hash_, - document->file_reference_.as_slice().str(), dc_id, DialogId(), std::move(thumb), - has_webp_thumbnail(sticker) ? PhotoFormat::Webp : PhotoFormat::Jpeg); + auto photo_size = get_photo_size(td_->file_manager_.get(), {FileType::Thumbnail, 0}, document_id, + document->access_hash_, document->file_reference_.as_slice().str(), dc_id, + DialogId(), std::move(thumb), thumbnail_format); if (photo_size.get_offset() == 0) { if (!thumbnail.file_id.is_valid()) { thumbnail = std::move(photo_size.get<0>()); diff --git a/td/telegram/StickersManager.h b/td/telegram/StickersManager.h index ed158732b..e67c83be1 100644 --- a/td/telegram/StickersManager.h +++ b/td/telegram/StickersManager.h @@ -90,7 +90,7 @@ class StickersManager : public Actor { vector get_installed_sticker_sets(bool is_masks, Promise &&promise); - bool has_webp_thumbnail(const tl_object_ptr &sticker); + static bool has_webp_thumbnail(const vector> &thumbnails); StickerSetId get_sticker_set_id(const tl_object_ptr &set_ptr);