Show only box(512,512) .webp as stickers.

This commit is contained in:
John Preston 2020-07-15 11:49:54 +04:00
parent 9cf15da2b1
commit 8aafe6ba0e
5 changed files with 18 additions and 18 deletions

View file

@ -37,8 +37,6 @@ enum {
AudioVoiceMsgMaxLength = 100 * 60, // 100 minutes AudioVoiceMsgMaxLength = 100 * 60, // 100 minutes
AudioVoiceMsgChannels = 2, // stereo 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 PreloadHeightsCount = 3, // when 3 screens to scroll left make a preload request
SearchPeopleLimit = 5, SearchPeopleLimit = 5,

View file

@ -47,7 +47,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace { namespace {
const auto kAnimatedStickerDimensions = QSize(512, 512); const auto kAnimatedStickerDimensions = QSize(
kStickerSideSize,
kStickerSideSize);
QString JoinStringList(const QStringList &list, const QString &separator) { QString JoinStringList(const QStringList &list, const QString &separator) {
const auto count = list.size(); const auto count = list.size();
@ -570,15 +572,11 @@ void DocumentData::setattributes(
}, [&](const MTPDdocumentAttributeHasStickers &data) { }, [&](const MTPDdocumentAttributeHasStickers &data) {
}); });
} }
if (type == StickerDocument) { if (type == StickerDocument
if (dimensions.width() <= 0 && (!GoodStickerDimensions(dimensions.width(), dimensions.height())
|| dimensions.height() <= 0 || (size > Storage::kMaxStickerBytesSize))) {
|| dimensions.width() > StickerMaxSize type = FileDocument;
|| dimensions.height() > StickerMaxSize _additional = nullptr;
|| !saveToCache()) {
type = FileDocument;
_additional = nullptr;
}
} }
if (isAudioFile() || isAnimation() || isVoiceMessage()) { if (isAudioFile() || isAnimation() || isVoiceMessage()) {
setMaybeSupportsStreaming(true); setMaybeSupportsStreaming(true);

View file

@ -320,6 +320,14 @@ enum DocumentType {
WallPaperDocument = 7, 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<uint64, uint64>; using MediaKey = QPair<uint64, uint64>;
class AudioMsgId { class AudioMsgId {

View file

@ -136,10 +136,9 @@ QSize Sticker::GetAnimatedEmojiSize(not_null<Main::Session*> session) {
QSize Sticker::GetAnimatedEmojiSize( QSize Sticker::GetAnimatedEmojiSize(
not_null<Main::Session*> session, not_null<Main::Session*> session,
QSize documentSize) { QSize documentSize) {
constexpr auto kIdealStickerSize = 512;
const auto zoom = GetEmojiStickerZoom(session); const auto zoom = GetEmojiStickerZoom(session);
const auto convert = [&](int size) { 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()) }; return { convert(documentSize.width()), convert(documentSize.height()) };
} }

View file

@ -842,10 +842,7 @@ void FileLoadTask::process() {
if (ValidateThumbDimensions(w, h)) { if (ValidateThumbDimensions(w, h)) {
isSticker = Core::IsMimeSticker(filemime) isSticker = Core::IsMimeSticker(filemime)
&& (w > 0) && GoodStickerDimensions(w, h)
&& (h > 0)
&& (w <= StickerMaxSize)
&& (h <= StickerMaxSize)
&& (filesize < Storage::kMaxStickerBytesSize); && (filesize < Storage::kMaxStickerBytesSize);
if (isSticker) { if (isSticker) {
attributes.push_back(MTP_documentAttributeSticker( attributes.push_back(MTP_documentAttributeSticker(