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);
}
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());
}
}

View File

@ -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 {

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);
}
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 {

View File

@ -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;

View File

@ -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);

View File

@ -37,7 +37,7 @@ FileBase::FileBase(not_null<Context*> 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;