From 254ca57bf328784e1c612f5c3618a8f2fdad04b0 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 4 Jan 2024 18:36:32 +0400 Subject: [PATCH] Fix webm emoji/stickers with unknown dimensions. --- Telegram/SourceFiles/data/data_document.cpp | 46 +++++++++++++++++---- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index 807d1927f..e5b1f5be6 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -48,6 +48,8 @@ namespace { constexpr auto kDefaultCoverThumbnailSize = 100; constexpr auto kMaxAllowedPreloadPrefix = 6 * 1024 * 1024; +constexpr auto kDefaultWebmEmojiSize = 100; +constexpr auto kDefaultWebmStickerLargerSize = kStickerSideSize; const auto kLottieStickerDimensions = QSize( kStickerSideSize, @@ -430,6 +432,42 @@ void DocumentData::setattributes( _flags |= Flag::HasAttachedStickers; }); } + + // Any "video/webm" file is treated as a video-sticker. + if (hasMimeType(u"video/webm"_q)) { + if (type == FileDocument) { + type = StickerDocument; + _additional = std::make_unique(); + } + if (type == StickerDocument) { + sticker()->type = StickerType::Webm; + } + } + + // If "video/webm" sticker without dimensions we set them to default. + if (const auto info = sticker(); info + && info->set + && info->type == StickerType::Webm + && dimensions.isEmpty()) { + if (info->setType == Data::StickersType::Emoji) { + // Always fixed. + dimensions = { kDefaultWebmEmojiSize, kDefaultWebmEmojiSize }; + } else if (info->setType == Data::StickersType::Stickers) { + // May have aspect != 1, so we count it from the thumbnail. + const auto thumbnail = QSize( + _thumbnail.location.width(), + _thumbnail.location.height() + ).scaled( + kDefaultWebmStickerLargerSize, + kDefaultWebmStickerLargerSize, + Qt::KeepAspectRatio); + if (!thumbnail.isEmpty()) { + dimensions = thumbnail; + } + } + } + + // Check sticker size/dimensions properties (for sticker of any type). if (type == StickerDocument && ((size > Storage::kMaxStickerBytesSize) || (!sticker()->isLottie() @@ -438,14 +476,8 @@ void DocumentData::setattributes( dimensions.height())))) { type = FileDocument; _additional = nullptr; - } else if (type == FileDocument - && hasMimeType(u"video/webm"_q) - && (size < Storage::kMaxStickerBytesSize) - && GoodStickerDimensions(dimensions.width(), dimensions.height())) { - type = StickerDocument; - _additional = std::make_unique(); - sticker()->type = StickerType::Webm; } + if (isAudioFile() || isAnimation() || isVoiceMessage()