Add location tracking to PhotoData

Add persistent file location storage for downloaded photos,
similar to DocumentData. This allows the app to remember
where a photo was saved and reuse that path.

Co-Authored-By: GLM-5 <contact@zhipuai.cn>
This commit is contained in:
Ilya Fedin
2026-03-09 18:04:17 +00:00
committed by John Preston
parent 6acc2633a5
commit 59ecfd67f0
2 changed files with 31 additions and 0 deletions
+24
View File
@@ -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<PhotoData*>(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);
+7
View File
@@ -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<Data::Session*> _owner;
Core::FileLocation _location;
};