diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 8fdac0c290..12e6c51ce1 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -1628,6 +1628,7 @@ namespace { int64 nowImageCacheSize = imageCacheSize(); if (nowImageCacheSize > serviceImageCacheSize + MemoryForImageCache) { App::forgetMedia(); + Auth().data().forgetMedia(); serviceImageCacheSize = imageCacheSize(); } } diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index aede8d5ade..088c87d8d7 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -1778,6 +1778,7 @@ void HistoryWidget::showHistory(const PeerId &peerId, MsgId showAtMsgId, bool re if (_peer) { App::forgetMedia(); + Auth().data().forgetMedia(); _serviceImageCacheSize = imageCacheSize(); Auth().downloader().clearPriorities(); diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index 8b29953f95..ffafea1f73 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -2880,6 +2880,10 @@ TaskId startImageLoad(const StorageKey &location, mtpFileLoader *loader) { std::make_unique(j->first, location, loader)); } +bool willImageLoad(const StorageKey &location) { + return _imagesMap.constFind(location) != _imagesMap.cend(); +} + int32 hasImages() { return _imagesMap.size(); } @@ -3024,6 +3028,10 @@ bool copyAudio(const StorageKey &oldLocation, const StorageKey &newLocation) { return true; } +bool willAudioLoad(const StorageKey &location) { + return _audiosMap.constFind(location) != _audiosMap.cend(); +} + int32 hasAudios() { return _audiosMap.size(); } @@ -3130,6 +3138,10 @@ TaskId startWebFileLoad(const QString &url, webFileLoader *loader) { std::make_unique(j->first, url, loader)); } +bool willWebFileLoad(const QString &url) { + return _webFilesMap.constFind(url) != _webFilesMap.cend(); +} + int32 hasWebFiles() { return _webFilesMap.size(); } diff --git a/Telegram/SourceFiles/storage/localstorage.h b/Telegram/SourceFiles/storage/localstorage.h index eaf33989c9..d27c092931 100644 --- a/Telegram/SourceFiles/storage/localstorage.h +++ b/Telegram/SourceFiles/storage/localstorage.h @@ -95,6 +95,7 @@ FileLocation readFileLocation(MediaKey location, bool check = true); void writeImage(const StorageKey &location, const ImagePtr &img); void writeImage(const StorageKey &location, const StorageImageSaved &jpeg, bool overwrite = true); TaskId startImageLoad(const StorageKey &location, mtpFileLoader *loader); +bool willImageLoad(const StorageKey &location); int32 hasImages(); qint64 storageImagesSize(); @@ -107,12 +108,14 @@ qint64 storageStickersSize(); void writeAudio(const StorageKey &location, const QByteArray &data, bool overwrite = true); TaskId startAudioLoad(const StorageKey &location, mtpFileLoader *loader); +bool willAudioLoad(const StorageKey &location); bool copyAudio(const StorageKey &oldLocation, const StorageKey &newLocation); int32 hasAudios(); qint64 storageAudiosSize(); void writeWebFile(const QString &url, const QByteArray &data, bool overwrite = true); TaskId startWebFileLoad(const QString &url, webFileLoader *loader); +bool willWebFileLoad(const QString &url); int32 hasWebFiles(); qint64 storageWebFilesSize(); diff --git a/Telegram/SourceFiles/ui/images.cpp b/Telegram/SourceFiles/ui/images.cpp index e5a31af8de..4c7796ea77 100644 --- a/Telegram/SourceFiles/ui/images.cpp +++ b/Telegram/SourceFiles/ui/images.cpp @@ -797,7 +797,9 @@ void Image::forget() const { if (_data.isNull()) return; invalidateSizeCache(); - if (_saved.isEmpty()) { + /*if (hasLocalCopy()) { + _saved.clear(); + } else */if (_saved.isEmpty()) { QBuffer buffer(&_saved); if (!_data.save(&buffer, _format)) { if (_data.save(&buffer, "PNG")) { @@ -1030,6 +1032,10 @@ int32 StorageImage::countHeight() const { return _location.height(); } +bool StorageImage::hasLocalCopy() const { + return Local::willImageLoad(storageKey(_location)); +} + void StorageImage::setInformation(int32 size, int32 width, int32 height) { _size = size; _location.setSize(width, height); @@ -1070,6 +1076,10 @@ int WebFileImage::countHeight() const { return _height; } +bool WebFileImage::hasLocalCopy() const { + return Local::willImageLoad(storageKey(_location)); +} + void WebFileImage::setInformation(int size, int width, int height) { _size = size; _width = width; @@ -1194,6 +1204,10 @@ int32 WebImage::countHeight() const { return _height; } +bool WebImage::hasLocalCopy() const { + return Local::willWebFileLoad(_url); +} + void WebImage::setInformation(int32 size, int32 width, int32 height) { _size = size; setSize(width, height); diff --git a/Telegram/SourceFiles/ui/images.h b/Telegram/SourceFiles/ui/images.h index 0a83ce8742..9bd98067a2 100644 --- a/Telegram/SourceFiles/ui/images.h +++ b/Telegram/SourceFiles/ui/images.h @@ -324,6 +324,10 @@ protected: return _data.height(); } + virtual bool hasLocalCopy() const { + return false; + } + mutable QByteArray _saved, _format; mutable bool _forgot; mutable QPixmap _data; @@ -413,6 +417,8 @@ protected: void setInformation(int32 size, int32 width, int32 height) override; FileLoader *createLoader(LoadFromCloudSetting fromCloud, bool autoLoading) override; + bool hasLocalCopy() const override; + StorageImageLocation _location; int32 _size; @@ -434,6 +440,8 @@ protected: return _box; } + bool hasLocalCopy() const override; + WebFileLocation _location; QSize _box; int _width = 0; @@ -496,6 +504,8 @@ protected: int32 countWidth() const override; int32 countHeight() const override; + bool hasLocalCopy() const override; + private: QString _url; QSize _box;