From 8aafe6ba0e5d98f75236869231819a22760ec0eb Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 15 Jul 2020 11:49:54 +0400 Subject: [PATCH] Show only box(512,512) .webp as stickers. --- Telegram/SourceFiles/config.h | 2 -- Telegram/SourceFiles/data/data_document.cpp | 18 ++++++++---------- Telegram/SourceFiles/data/data_types.h | 8 ++++++++ .../view/media/history_view_sticker.cpp | 3 +-- .../SourceFiles/storage/localimageloader.cpp | 5 +---- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index defe4723a..40d01e9fc 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -37,8 +37,6 @@ enum { AudioVoiceMsgMaxLength = 100 * 60, // 100 minutes AudioVoiceMsgChannels = 2, // stereo - StickerMaxSize = 2048, // 2048x2048 is a max image size for sticker - PreloadHeightsCount = 3, // when 3 screens to scroll left make a preload request SearchPeopleLimit = 5, diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index 5b0092d2a..c8b8156e4 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -47,7 +47,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace { -const auto kAnimatedStickerDimensions = QSize(512, 512); +const auto kAnimatedStickerDimensions = QSize( + kStickerSideSize, + kStickerSideSize); QString JoinStringList(const QStringList &list, const QString &separator) { const auto count = list.size(); @@ -570,15 +572,11 @@ void DocumentData::setattributes( }, [&](const MTPDdocumentAttributeHasStickers &data) { }); } - if (type == StickerDocument) { - if (dimensions.width() <= 0 - || dimensions.height() <= 0 - || dimensions.width() > StickerMaxSize - || dimensions.height() > StickerMaxSize - || !saveToCache()) { - type = FileDocument; - _additional = nullptr; - } + if (type == StickerDocument + && (!GoodStickerDimensions(dimensions.width(), dimensions.height()) + || (size > Storage::kMaxStickerBytesSize))) { + type = FileDocument; + _additional = nullptr; } if (isAudioFile() || isAnimation() || isVoiceMessage()) { setMaybeSupportsStreaming(true); diff --git a/Telegram/SourceFiles/data/data_types.h b/Telegram/SourceFiles/data/data_types.h index b66ea8918..4f06cbea0 100644 --- a/Telegram/SourceFiles/data/data_types.h +++ b/Telegram/SourceFiles/data/data_types.h @@ -320,6 +320,14 @@ enum DocumentType { WallPaperDocument = 7, }; +inline constexpr auto kStickerSideSize = 512; + +[[nodiscard]] inline bool GoodStickerDimensions(int width, int height) { + return (width > 0 && width <= kStickerSideSize) + && (height > 0 && height <= kStickerSideSize) + && (width == kStickerSideSize || height == kStickerSideSize); +} + using MediaKey = QPair; class AudioMsgId { diff --git a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp index 4bd2295ab..5cc833835 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp @@ -136,10 +136,9 @@ QSize Sticker::GetAnimatedEmojiSize(not_null session) { QSize Sticker::GetAnimatedEmojiSize( not_null session, QSize documentSize) { - constexpr auto kIdealStickerSize = 512; const auto zoom = GetEmojiStickerZoom(session); const auto convert = [&](int size) { - return int(size * st::maxStickerSize * zoom / kIdealStickerSize); + return int(size * st::maxStickerSize * zoom / kStickerSideSize); }; return { convert(documentSize.width()), convert(documentSize.height()) }; } diff --git a/Telegram/SourceFiles/storage/localimageloader.cpp b/Telegram/SourceFiles/storage/localimageloader.cpp index 7d7a9bcb6..ae4ab6522 100644 --- a/Telegram/SourceFiles/storage/localimageloader.cpp +++ b/Telegram/SourceFiles/storage/localimageloader.cpp @@ -842,10 +842,7 @@ void FileLoadTask::process() { if (ValidateThumbDimensions(w, h)) { isSticker = Core::IsMimeSticker(filemime) - && (w > 0) - && (h > 0) - && (w <= StickerMaxSize) - && (h <= StickerMaxSize) + && GoodStickerDimensions(w, h) && (filesize < Storage::kMaxStickerBytesSize); if (isSticker) { attributes.push_back(MTP_documentAttributeSticker(