diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index 03a3d2de82..fd1aa8d789 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -381,7 +381,7 @@ void StickerSetBox::Inner::paintEvent(QPaintEvent *e) { p.setOpacity(1); } - bool goodThumb = !doc->thumb->isNull() && ((doc->thumb->width() >= 128) || (doc->thumb->height() >= 128)); + const auto goodThumb = doc->hasGoodStickerThumb(); if (goodThumb) { doc->thumb->load(); } else { @@ -389,7 +389,9 @@ void StickerSetBox::Inner::paintEvent(QPaintEvent *e) { doc->automaticLoad(0); } if (doc->sticker()->img->isNull() && doc->loaded(DocumentData::FilePathResolveChecked)) { - doc->sticker()->img = doc->data().isEmpty() ? ImagePtr(doc->filepath()) : ImagePtr(doc->data()); + doc->sticker()->img = doc->data().isEmpty() + ? ImagePtr(doc->filepath()) + : ImagePtr(doc->data()); } } diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index 1c786f6c91..2f52431cca 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -558,7 +558,7 @@ void FieldAutocompleteInner::paintEvent(QPaintEvent *e) { App::roundRect(p, QRect(tl, st::stickerPanSize), st::emojiPanHover, StickerHoverCorners); } - bool goodThumb = !sticker->thumb->isNull() && ((sticker->thumb->width() >= 128) || (sticker->thumb->height() >= 128)); + const auto goodThumb = sticker->hasGoodStickerThumb(); if (goodThumb) { sticker->thumb->load(); } else { diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index 82e167ed43..94cb5950eb 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -1306,7 +1306,7 @@ void StickersListWidget::paintSticker(Painter &p, Set &set, int y, int index, bo App::roundRect(p, QRect(tl, _singleSize), st::emojiPanHover, StickerHoverCorners); } - auto goodThumb = !sticker->thumb->isNull() && ((sticker->thumb->width() >= 128) || (sticker->thumb->height() >= 128)); + const auto goodThumb = sticker->hasGoodStickerThumb(); if (goodThumb) { sticker->thumb->load(); } else { @@ -1755,9 +1755,7 @@ void StickersListWidget::preloadImages() { auto sticker = sets[i].pack.at(j); if (!sticker || !sticker->sticker()) continue; - bool goodThumb = !sticker->thumb->isNull() - && ((sticker->thumb->width() >= 128) - || (sticker->thumb->height() >= 128)); + const auto goodThumb = sticker->hasGoodStickerThumb(); if (goodThumb) { sticker->thumb->load(); } else { diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index e35e5ba77d..5f7745fa39 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -1094,6 +1094,11 @@ void DocumentData::recountIsImage() { _duration = fileIsImage(filename(), mimeString()) ? 1 : -1; // hack } +bool DocumentData::hasGoodStickerThumb() const { + return !thumb->isNull() + && ((thumb->width() >= 128) || (thumb->height() >= 128)); +} + bool DocumentData::setRemoteVersion(int32 version) { if (_version == version) { return false; diff --git a/Telegram/SourceFiles/data/data_document.h b/Telegram/SourceFiles/data/data_document.h index bede848fad..dad17dd43e 100644 --- a/Telegram/SourceFiles/data/data_document.h +++ b/Telegram/SourceFiles/data/data_document.h @@ -145,6 +145,8 @@ public: _data = data; } + bool hasGoodStickerThumb() const; + bool setRemoteVersion(int32 version); // Returns true if version has changed. void setRemoteLocation(int32 dc, uint64 access); void setContentUrl(const QString &url); diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp index ee5fa45fbf..dc22065d60 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp @@ -37,7 +37,7 @@ FileBase::FileBase(not_null context, DocumentData *document) : ItemBas } DocumentData *FileBase::getShownDocument() const { - if (DocumentData *result = getDocument()) { + if (const auto result = getDocument()) { return result; } return getResultDocument(); @@ -371,15 +371,15 @@ void Sticker::initDimensions() { } void Sticker::preload() const { - if (DocumentData *document = getShownDocument()) { - bool goodThumb = !document->thumb->isNull() && ((document->thumb->width() >= 128) || (document->thumb->height() >= 128)); + if (const auto document = getShownDocument()) { + const auto goodThumb = document->hasGoodStickerThumb(); if (goodThumb) { document->thumb->load(); } else { document->checkSticker(); } } else { - ImagePtr thumb = getResultThumb(); + const auto thumb = getResultThumb(); if (!thumb->isNull()) { thumb->load(); } @@ -437,16 +437,18 @@ QSize Sticker::getThumbSize() const { } void Sticker::prepareThumb() const { - if (DocumentData *document = getShownDocument()) { - bool goodThumb = !document->thumb->isNull() && ((document->thumb->width() >= 128) || (document->thumb->height() >= 128)); + if (const auto document = getShownDocument()) { + const auto goodThumb = document->hasGoodStickerThumb(); if (goodThumb) { document->thumb->load(); } else { document->checkSticker(); } - ImagePtr sticker = goodThumb ? document->thumb : document->sticker()->img; - if (!_thumbLoaded && sticker->loaded()) { + const auto sticker = goodThumb + ? document->thumb + : document->sticker()->img; + if (!_thumbLoaded && !sticker->isNull() && sticker->loaded()) { QSize thumbSize = getThumbSize(); _thumb = sticker->pix(thumbSize.width(), thumbSize.height()); _thumbLoaded = true;