Fix sticker inline bot results.

Fixes #3317.
This commit is contained in:
John Preston 2018-06-03 20:48:00 +03:00
parent e62e7d1de2
commit 2bd8737410
6 changed files with 24 additions and 15 deletions

View File

@ -381,7 +381,7 @@ void StickerSetBox::Inner::paintEvent(QPaintEvent *e) {
p.setOpacity(1); p.setOpacity(1);
} }
bool goodThumb = !doc->thumb->isNull() && ((doc->thumb->width() >= 128) || (doc->thumb->height() >= 128)); const auto goodThumb = doc->hasGoodStickerThumb();
if (goodThumb) { if (goodThumb) {
doc->thumb->load(); doc->thumb->load();
} else { } else {
@ -389,7 +389,9 @@ void StickerSetBox::Inner::paintEvent(QPaintEvent *e) {
doc->automaticLoad(0); doc->automaticLoad(0);
} }
if (doc->sticker()->img->isNull() && doc->loaded(DocumentData::FilePathResolveChecked)) { 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());
} }
} }

View File

@ -558,7 +558,7 @@ void FieldAutocompleteInner::paintEvent(QPaintEvent *e) {
App::roundRect(p, QRect(tl, st::stickerPanSize), st::emojiPanHover, StickerHoverCorners); 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) { if (goodThumb) {
sticker->thumb->load(); sticker->thumb->load();
} else { } else {

View File

@ -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); 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) { if (goodThumb) {
sticker->thumb->load(); sticker->thumb->load();
} else { } else {
@ -1755,9 +1755,7 @@ void StickersListWidget::preloadImages() {
auto sticker = sets[i].pack.at(j); auto sticker = sets[i].pack.at(j);
if (!sticker || !sticker->sticker()) continue; if (!sticker || !sticker->sticker()) continue;
bool goodThumb = !sticker->thumb->isNull() const auto goodThumb = sticker->hasGoodStickerThumb();
&& ((sticker->thumb->width() >= 128)
|| (sticker->thumb->height() >= 128));
if (goodThumb) { if (goodThumb) {
sticker->thumb->load(); sticker->thumb->load();
} else { } else {

View File

@ -1094,6 +1094,11 @@ void DocumentData::recountIsImage() {
_duration = fileIsImage(filename(), mimeString()) ? 1 : -1; // hack _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) { bool DocumentData::setRemoteVersion(int32 version) {
if (_version == version) { if (_version == version) {
return false; return false;

View File

@ -145,6 +145,8 @@ public:
_data = data; _data = data;
} }
bool hasGoodStickerThumb() const;
bool setRemoteVersion(int32 version); // Returns true if version has changed. bool setRemoteVersion(int32 version); // Returns true if version has changed.
void setRemoteLocation(int32 dc, uint64 access); void setRemoteLocation(int32 dc, uint64 access);
void setContentUrl(const QString &url); void setContentUrl(const QString &url);

View File

@ -37,7 +37,7 @@ FileBase::FileBase(not_null<Context*> context, DocumentData *document) : ItemBas
} }
DocumentData *FileBase::getShownDocument() const { DocumentData *FileBase::getShownDocument() const {
if (DocumentData *result = getDocument()) { if (const auto result = getDocument()) {
return result; return result;
} }
return getResultDocument(); return getResultDocument();
@ -371,15 +371,15 @@ void Sticker::initDimensions() {
} }
void Sticker::preload() const { void Sticker::preload() const {
if (DocumentData *document = getShownDocument()) { if (const auto document = getShownDocument()) {
bool goodThumb = !document->thumb->isNull() && ((document->thumb->width() >= 128) || (document->thumb->height() >= 128)); const auto goodThumb = document->hasGoodStickerThumb();
if (goodThumb) { if (goodThumb) {
document->thumb->load(); document->thumb->load();
} else { } else {
document->checkSticker(); document->checkSticker();
} }
} else { } else {
ImagePtr thumb = getResultThumb(); const auto thumb = getResultThumb();
if (!thumb->isNull()) { if (!thumb->isNull()) {
thumb->load(); thumb->load();
} }
@ -437,16 +437,18 @@ QSize Sticker::getThumbSize() const {
} }
void Sticker::prepareThumb() const { void Sticker::prepareThumb() const {
if (DocumentData *document = getShownDocument()) { if (const auto document = getShownDocument()) {
bool goodThumb = !document->thumb->isNull() && ((document->thumb->width() >= 128) || (document->thumb->height() >= 128)); const auto goodThumb = document->hasGoodStickerThumb();
if (goodThumb) { if (goodThumb) {
document->thumb->load(); document->thumb->load();
} else { } else {
document->checkSticker(); document->checkSticker();
} }
ImagePtr sticker = goodThumb ? document->thumb : document->sticker()->img; const auto sticker = goodThumb
if (!_thumbLoaded && sticker->loaded()) { ? document->thumb
: document->sticker()->img;
if (!_thumbLoaded && !sticker->isNull() && sticker->loaded()) {
QSize thumbSize = getThumbSize(); QSize thumbSize = getThumbSize();
_thumb = sticker->pix(thumbSize.width(), thumbSize.height()); _thumb = sticker->pix(thumbSize.width(), thumbSize.height());
_thumbLoaded = true; _thumbLoaded = true;