Clear DocumentMedia in ReplyPreview.

This commit is contained in:
John Preston 2020-05-21 15:40:10 +04:00
parent 44ec55b6a8
commit d64014c995
4 changed files with 22 additions and 8 deletions

View File

@ -627,11 +627,13 @@ void DocumentData::updateThumbnails(
loadThumbnail(origin);
}
if (!thumbnail.bytes.isEmpty()) {
owner().cache().putIfEmpty(
_thumbnailLocation.file().cacheKey(),
Storage::Cache::Database::TaggedValue(
base::duplicate(thumbnail.bytes),
Data::kImageCacheTag));
if (const auto cacheKey = _thumbnailLocation.file().cacheKey()) {
owner().cache().putIfEmpty(
cacheKey,
Storage::Cache::Database::TaggedValue(
base::duplicate(thumbnail.bytes),
Data::kImageCacheTag));
}
}
}
}

View File

@ -17,8 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Data {
ReplyPreview::ReplyPreview(not_null<DocumentData*> document)
: _document(document)
, _documentMedia(_document->createMediaView()) {
: _document(document) {
}
ReplyPreview::ReplyPreview(not_null<PhotoData*> photo)
@ -59,7 +58,13 @@ void ReplyPreview::prepare(not_null<Image*> image, Images::Options options) {
}
Image *ReplyPreview::image(Data::FileOrigin origin) {
if (_checked) {
return _image.get();
}
if (_document) {
if (!_documentMedia) {
_documentMedia = _document->createMediaView();
}
const auto thumbnail = _documentMedia->thumbnail();
if (!_image || (!_good && thumbnail)) {
const auto option = _document->isVideoMessage()
@ -73,6 +78,10 @@ Image *ReplyPreview::image(Data::FileOrigin origin) {
prepare(image, option | Images::Option::Blurred);
}
}
if (thumbnail || !_document->hasThumbnail()) {
_checked = true;
_documentMedia = nullptr;
}
}
} else {
Assert(_photo != nullptr);

View File

@ -27,6 +27,7 @@ private:
std::unique_ptr<Image> _image;
bool _good = false;
bool _checked = false;
DocumentData *_document = nullptr;
PhotoData *_photo = nullptr;
std::shared_ptr<DocumentMedia> _documentMedia;

View File

@ -133,10 +133,12 @@ int Gif::resizeGetHeight(int width) {
void Gif::paint(Painter &p, const QRect &clip, const PaintContext *context) const {
const auto document = getShownDocument();
const auto displayLoading = document->displayLoading();
ensureDataMediaCreated(document);
_dataMedia->automaticLoad(fileOrigin(), nullptr);
bool loaded = _dataMedia->loaded(), loading = document->loading(), displayLoading = document->displayLoading();
bool loaded = _dataMedia->loaded(), loading = document->loading();
if (loaded
&& !_gif
&& !_gif.isBad()