diff --git a/Telegram/SourceFiles/data/data_photo.cpp b/Telegram/SourceFiles/data/data_photo.cpp index 0a2d37f8f3..c354ca551b 100644 --- a/Telegram/SourceFiles/data/data_photo.cpp +++ b/Telegram/SourceFiles/data/data_photo.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "data/data_photo.h" +#include "data/data_document.h" #include "data/data_session.h" #include "data/data_reply_preview.h" #include "data/data_photo_media.h" @@ -15,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item.h" #include "media/streaming/media_streaming_loader_local.h" #include "media/streaming/media_streaming_loader_mtproto.h" +#include "storage/storage_account.h" #include "storage/file_download.h" #include "core/application.h" @@ -475,6 +477,28 @@ int PhotoData::height() const { return _images[PhotoSizeIndex(PhotoSize::Large)].location.height(); } +MediaKey PhotoData::mediaKey() const { + return ::mediaKey(UnknownFileLocation, _dc, id); +} + +const Core::FileLocation &PhotoData::location(bool check) const { + if (check && !_location.check()) { + const auto location = session().local().readFileLocation(mediaKey()); + const auto that = const_cast(this); + if (!location.inMediaCache()) { + that->_location = location; + } + } + return _location; +} + +void PhotoData::setLocation(const Core::FileLocation &loc) { + if (!loc.inMediaCache() && loc.check()) { + _location = loc; + session().local().writeFileLocation(mediaKey(), _location); + } +} + Data::CloudFile &PhotoData::videoFile(PhotoSize size) { Expects(_videoSizes != nullptr); diff --git a/Telegram/SourceFiles/data/data_photo.h b/Telegram/SourceFiles/data/data_photo.h index 3cd749a715..f33078082a 100644 --- a/Telegram/SourceFiles/data/data_photo.h +++ b/Telegram/SourceFiles/data/data_photo.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_types.h" #include "data/data_cloud_file.h" +#include "core/file_location.h" namespace Main { class Session; @@ -160,6 +161,10 @@ public: [[nodiscard]] int width() const; [[nodiscard]] int height() const; + [[nodiscard]] MediaKey mediaKey() const; + [[nodiscard]] const Core::FileLocation &location(bool check) const; + void setLocation(const Core::FileLocation &loc); + PhotoId id = 0; PeerData *peer = nullptr; // for chat and channel photos connection @@ -195,4 +200,6 @@ private: not_null _owner; + Core::FileLocation _location; + };