Improve StickersManager::has_webp_thumbnail.
This commit is contained in:
parent
8430ba6d19
commit
a36f020084
@ -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) {
|
||||
|
@ -1830,8 +1830,19 @@ FileId StickersManager::on_get_sticker(unique_ptr<Sticker> new_sticker, bool rep
|
||||
return file_id;
|
||||
}
|
||||
|
||||
bool StickersManager::has_webp_thumbnail(const tl_object_ptr<telegram_api::documentAttributeSticker> &sticker) {
|
||||
// server tries to always replace user-provided thumbnail with server-side webp thumbnail
|
||||
bool StickersManager::has_webp_thumbnail(const vector<tl_object_ptr<telegram_api::PhotoSize>> &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<int64, FileId> 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>());
|
||||
|
@ -90,7 +90,7 @@ class StickersManager : public Actor {
|
||||
|
||||
vector<StickerSetId> get_installed_sticker_sets(bool is_masks, Promise<Unit> &&promise);
|
||||
|
||||
bool has_webp_thumbnail(const tl_object_ptr<telegram_api::documentAttributeSticker> &sticker);
|
||||
static bool has_webp_thumbnail(const vector<tl_object_ptr<telegram_api::PhotoSize>> &thumbnails);
|
||||
|
||||
StickerSetId get_sticker_set_id(const tl_object_ptr<telegram_api::InputStickerSet> &set_ptr);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user