diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index c28e48dba..cecfd003a 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -851,7 +851,7 @@ void DocumentData::save( status = FileReady; if (hasWebLocation()) { _loader = new mtpFileLoader( - &_urlLocation, + _urlLocation, size, fromCloud, autoLoading, @@ -865,10 +865,14 @@ void DocumentData::save( cacheTag()); } else { _loader = new mtpFileLoader( - _dc, - id, - _access, - _fileReference, + StorageFileLocation( + _dc, + session().userId(), + MTP_inputDocumentFileLocation( + MTP_long(id), + MTP_long(_access), + MTP_bytes(_fileReference), + MTP_string(QString()))), origin, locationType(), toFile, @@ -1209,7 +1213,7 @@ auto DocumentData::createStreamingLoader(Data::FileOrigin origin) const } bool DocumentData::hasWebLocation() const { - return _urlLocation.dc() != 0 && _urlLocation.accessHash() != 0; + return !_urlLocation.url().isEmpty(); } bool DocumentData::isNull() const { diff --git a/Telegram/SourceFiles/data/data_media_types.cpp b/Telegram/SourceFiles/data/data_media_types.cpp index faf44088b..61cdf67e3 100644 --- a/Telegram/SourceFiles/data/data_media_types.cpp +++ b/Telegram/SourceFiles/data/data_media_types.cpp @@ -403,7 +403,7 @@ bool MediaPhoto::updateSentMedia(const MTPMessageMedia &media) { return; } parent()->history()->owner().cache().putIfEmpty( - Data::StorageCacheKey(key), + key.file().cacheKey(), Storage::Cache::Database::TaggedValue( std::move(size.bytes), Data::kImageCacheTag)); diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 81bc16757..493a345d9 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -2029,7 +2029,6 @@ DocumentData *Session::documentFromWeb( int32(0), // data.vsize.v StorageImageLocation()); result->setWebLocation(WebFileLocation( - Global::WebFileDcId(), data.vurl.v, data.vaccess_hash.v)); return result; diff --git a/Telegram/SourceFiles/data/data_types.cpp b/Telegram/SourceFiles/data/data_types.cpp index b27e4efa1..d99ca53bf 100644 --- a/Telegram/SourceFiles/data/data_types.cpp +++ b/Telegram/SourceFiles/data/data_types.cpp @@ -61,12 +61,9 @@ Storage::Cache::Key DocumentThumbCacheKey(int32 dcId, uint64 id) { }; } -Storage::Cache::Key StorageCacheKey(const StorageImageLocation &location) { - return location.file().cacheKey(); -} - Storage::Cache::Key WebDocumentCacheKey(const WebFileLocation &location) { - const auto dcId = uint64(location.dc()) & 0xFFULL; + const auto CacheDcId = cTestMode() ? 2 : 4; + const auto dcId = uint64(CacheDcId) & 0xFFULL; const auto &url = location.url(); const auto hash = openssl::Sha256(bytes::make_span(url)); const auto bytes = bytes::make_span(hash); diff --git a/Telegram/SourceFiles/data/data_types.h b/Telegram/SourceFiles/data/data_types.h index a47007b1a..3be72a4b2 100644 --- a/Telegram/SourceFiles/data/data_types.h +++ b/Telegram/SourceFiles/data/data_types.h @@ -44,7 +44,6 @@ struct UploadState { Storage::Cache::Key DocumentCacheKey(int32 dcId, uint64 id); Storage::Cache::Key DocumentThumbCacheKey(int32 dcId, uint64 id); -Storage::Cache::Key StorageCacheKey(const StorageImageLocation &location); Storage::Cache::Key WebDocumentCacheKey(const WebFileLocation &location); Storage::Cache::Key UrlCacheKey(const QString &location); Storage::Cache::Key GeoPointCacheKey(const GeoPointLocation &location); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index edc4600ca..702a11468 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1246,7 +1246,7 @@ void MainWidget::exportTopBarHeightUpdated() { } void MainWidget::documentLoadProgress(FileLoader *loader) { - if (auto documentId = loader ? loader->objId() : 0) { + if (const auto documentId = loader ? loader->objId() : 0) { documentLoadProgress(session().data().document(documentId)); } } @@ -1261,10 +1261,10 @@ void MainWidget::documentLoadProgress(DocumentData *document) { } void MainWidget::documentLoadFailed(FileLoader *loader, bool started) { - auto documentId = loader ? loader->objId() : 0; + const auto documentId = loader ? loader->objId() : 0; if (!documentId) return; - auto document = session().data().document(documentId); + const auto document = session().data().document(documentId); if (started) { const auto origin = loader->fileOrigin(); const auto failedFileName = loader->fileName(); diff --git a/Telegram/SourceFiles/passport/passport_form_controller.cpp b/Telegram/SourceFiles/passport/passport_form_controller.cpp index dd15271c0..a5744ad02 100644 --- a/Telegram/SourceFiles/passport/passport_form_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_form_controller.cpp @@ -1712,10 +1712,12 @@ void FormController::loadFile(File &file) { const auto [j, ok] = _fileLoaders.emplace( key, std::make_unique( - file.dcId, - file.id, - file.accessHash, - QByteArray(), // file_reference + StorageFileLocation( + file.dcId, + Auth().userId(), + MTP_inputSecureFileLocation( + MTP_long(file.id), + MTP_long(file.accessHash))), Data::FileOrigin(), SecureFileLocation, QString(), diff --git a/Telegram/SourceFiles/storage/file_download.cpp b/Telegram/SourceFiles/storage/file_download.cpp index 8dd948018..2d6cd3514 100644 --- a/Telegram/SourceFiles/storage/file_download.cpp +++ b/Telegram/SourceFiles/storage/file_download.cpp @@ -527,36 +527,7 @@ void FileLoader::startLoading(bool loadFirst, bool prior) { } mtpFileLoader::mtpFileLoader( - not_null location, - Data::FileOrigin origin, - int32 size, - LoadFromCloudSetting fromCloud, - bool autoLoading, - uint8 cacheTag) -: FileLoader( - QString(), - size, - UnknownFileLocation, - LoadToCacheAsWell, - fromCloud, - autoLoading, - cacheTag) -, _dcId(location->file().dcId()) -, _location(location) -, _origin(origin) { - auto shiftedDcId = MTP::downloadDcId(_dcId, 0); - auto i = queues.find(shiftedDcId); - if (i == queues.cend()) { - i = queues.insert(shiftedDcId, FileLoaderQueue(kMaxFileQueries)); - } - _queue = &i.value(); -} - -mtpFileLoader::mtpFileLoader( - int32 dc, - uint64 id, - uint64 accessHash, - const QByteArray &fileReference, + const StorageFileLocation &location, Data::FileOrigin origin, LocationType type, const QString &to, @@ -573,12 +544,9 @@ mtpFileLoader::mtpFileLoader( fromCloud, autoLoading, cacheTag) -, _dcId(dc) -, _id(id) -, _accessHash(accessHash) -, _fileReference(fileReference) +, _location(location) , _origin(origin) { - auto shiftedDcId = MTP::downloadDcId(_dcId, 0); + auto shiftedDcId = MTP::downloadDcId(dcId(), 0); auto i = queues.find(shiftedDcId); if (i == queues.cend()) { i = queues.insert(shiftedDcId, FileLoaderQueue(kMaxFileQueries)); @@ -587,7 +555,7 @@ mtpFileLoader::mtpFileLoader( } mtpFileLoader::mtpFileLoader( - const WebFileLocation *location, + const WebFileLocation &location, int32 size, LoadFromCloudSetting fromCloud, bool autoLoading, @@ -600,9 +568,8 @@ mtpFileLoader::mtpFileLoader( fromCloud, autoLoading, cacheTag) -, _dcId(location->dc()) -, _urlLocation(location) { - auto shiftedDcId = MTP::downloadDcId(_dcId, 0); +, _location(location) { + auto shiftedDcId = MTP::downloadDcId(dcId(), 0); auto i = queues.find(shiftedDcId); if (i == queues.cend()) { i = queues.insert(shiftedDcId, FileLoaderQueue(kMaxFileQueries)); @@ -611,7 +578,7 @@ mtpFileLoader::mtpFileLoader( } mtpFileLoader::mtpFileLoader( - const GeoPointLocation *location, + const GeoPointLocation &location, int32 size, LoadFromCloudSetting fromCloud, bool autoLoading, @@ -624,9 +591,8 @@ mtpFileLoader::mtpFileLoader( fromCloud, autoLoading, cacheTag) -, _dcId(Global::WebFileDcId()) -, _geoLocation(location) { - auto shiftedDcId = MTP::downloadDcId(_dcId, 0); +, _location(location) { + auto shiftedDcId = MTP::downloadDcId(dcId(), 0); auto i = queues.find(shiftedDcId); if (i == queues.cend()) { i = queues.insert(shiftedDcId, FileLoaderQueue(kMaxFileQueries)); @@ -635,33 +601,34 @@ mtpFileLoader::mtpFileLoader( } int32 mtpFileLoader::currentOffset(bool includeSkipped) const { - return (_fileIsOpen ? _file.size() : _data.size()) - (includeSkipped ? 0 : _skippedBytes); + return (_fileIsOpen ? _file.size() : _data.size()) + - (includeSkipped ? 0 : _skippedBytes); } Data::FileOrigin mtpFileLoader::fileOrigin() const { return _origin; } +uint64 mtpFileLoader::objId() const { + if (const auto storage = base::get_if(&_location)) { + return storage->objectId(); + } + return 0; +} + void mtpFileLoader::refreshFileReferenceFrom( const Data::UpdatedFileReferences &updates, int requestId, const QByteArray ¤t) { - if (_location) { - _location->refreshFileReference(updates); - if (_location->fileReference() == current) { + if (const auto storage = base::get_if(&_location)) { + storage->refreshFileReference(updates); + if (storage->fileReference() == current) { cancel(true); return; } } else { - const auto i = updates.data.find( - Data::DocumentFileLocationId{ _id }); - if (i != end(updates.data) && !i->second.isEmpty()) { - _fileReference = i->second; - } - if (_fileReference == current) { - cancel(true); - return; - } + cancel(true); + return; } const auto offset = finishSentRequestGetOffset(requestId); makeRequest(offset); @@ -679,6 +646,13 @@ bool mtpFileLoader::loadPart() { return true; } +MTP::DcId mtpFileLoader::dcId() const { + if (const auto storage = base::get_if(&_location)) { + return storage->dcId(); + } + return Global::WebFileDcId(); +} + int mtpFileLoader::partSize() const { return kDownloadCdnPartSize; @@ -697,103 +671,82 @@ int mtpFileLoader::partSize() const { mtpFileLoader::RequestData mtpFileLoader::prepareRequest(int offset) const { auto result = RequestData(); - result.dcId = _cdnDcId ? _cdnDcId : _dcId; - result.dcIndex = _size ? _downloader->chooseDcIndexForRequest(result.dcId) : 0; + result.dcId = _cdnDcId ? _cdnDcId : dcId(); + result.dcIndex = _size + ? _downloader->chooseDcIndexForRequest(result.dcId) + : 0; result.offset = offset; return result; } +mtpRequestId mtpFileLoader::sendRequest(const RequestData &requestData) { + const auto offset = requestData.offset; + const auto limit = partSize(); + const auto shiftedDcId = MTP::downloadDcId( + requestData.dcId, + requestData.dcIndex); + if (_cdnDcId) { + Assert(requestData.dcId == _cdnDcId); + return MTP::send( + MTPupload_GetCdnFile( + MTP_bytes(_cdnToken), + MTP_int(offset), + MTP_int(limit)), + rpcDone(&mtpFileLoader::cdnPartLoaded), + rpcFail(&mtpFileLoader::cdnPartFailed), + shiftedDcId, + 50); + } + return _location.match([&](const WebFileLocation &location) { + return MTP::send( + MTPupload_GetWebFile( + MTP_inputWebFileLocation( + MTP_bytes(location.url()), + MTP_long(location.accessHash())), + MTP_int(offset), + MTP_int(limit)), + rpcDone(&mtpFileLoader::webPartLoaded), + rpcFail(&mtpFileLoader::partFailed), + shiftedDcId, + 50); + }, [&](const GeoPointLocation &location) { + return MTP::send( + MTPupload_GetWebFile( + MTP_inputWebFileGeoPointLocation( + MTP_inputGeoPoint( + MTP_double(location.lat), + MTP_double(location.lon)), + MTP_long(location.access), + MTP_int(location.width), + MTP_int(location.height), + MTP_int(location.zoom), + MTP_int(location.scale)), + MTP_int(offset), + MTP_int(limit)), + rpcDone(&mtpFileLoader::webPartLoaded), + rpcFail(&mtpFileLoader::partFailed), + shiftedDcId, + 50); + }, [&](const StorageFileLocation &location) { + return MTP::send( + MTPupload_GetFile( + location.tl(Auth().userId()), + MTP_int(offset), + MTP_int(limit)), + rpcDone(&mtpFileLoader::normalPartLoaded), + rpcFail( + &mtpFileLoader::normalPartFailed, + location.fileReference()), + shiftedDcId, + 50); + }); +} + void mtpFileLoader::makeRequest(int offset) { Expects(!_finished); auto requestData = prepareRequest(offset); - auto send = [this, &requestData] { - auto offset = requestData.offset; - auto limit = partSize(); - auto shiftedDcId = MTP::downloadDcId(requestData.dcId, requestData.dcIndex); - if (_cdnDcId) { - Assert(requestData.dcId == _cdnDcId); - return MTP::send( - MTPupload_GetCdnFile( - MTP_bytes(_cdnToken), - MTP_int(offset), - MTP_int(limit)), - rpcDone(&mtpFileLoader::cdnPartLoaded), - rpcFail(&mtpFileLoader::cdnPartFailed), - shiftedDcId, - 50); - } else if (_urlLocation) { - Assert(requestData.dcId == _dcId); - return MTP::send( - MTPupload_GetWebFile( - MTP_inputWebFileLocation( - MTP_bytes(_urlLocation->url()), - MTP_long(_urlLocation->accessHash())), - MTP_int(offset), - MTP_int(limit)), - rpcDone(&mtpFileLoader::webPartLoaded), - rpcFail(&mtpFileLoader::partFailed), - shiftedDcId, - 50); - } else if (_geoLocation) { - Assert(requestData.dcId == _dcId); - return MTP::send( - MTPupload_GetWebFile( - MTP_inputWebFileGeoPointLocation( - MTP_inputGeoPoint( - MTP_double(_geoLocation->lat), - MTP_double(_geoLocation->lon)), - MTP_long(_geoLocation->access), - MTP_int(_geoLocation->width), - MTP_int(_geoLocation->height), - MTP_int(_geoLocation->zoom), - MTP_int(_geoLocation->scale)), - MTP_int(offset), - MTP_int(limit)), - rpcDone(&mtpFileLoader::webPartLoaded), - rpcFail(&mtpFileLoader::partFailed), - shiftedDcId, - 50); - } else { - Assert(requestData.dcId == _dcId); - return MTP::send( - MTPupload_GetFile( - computeLocation(), - MTP_int(offset), - MTP_int(limit)), - rpcDone(&mtpFileLoader::normalPartLoaded), - rpcFail( - &mtpFileLoader::normalPartFailed, - computeFileReference()), - shiftedDcId, - 50); - } - }; - placeSentRequest(send(), requestData); -} - -MTPInputFileLocation mtpFileLoader::computeLocation() const { - if (_location) { - return _location->file().tl(Auth().userId()); - } else if (_locationType == SecureFileLocation) { - return MTP_inputSecureFileLocation( - MTP_long(_id), - MTP_long(_accessHash)); - } - return MTP_inputDocumentFileLocation( - MTP_long(_id), - MTP_long(_accessHash), - MTP_bytes(_fileReference), - MTP_string(QString())); -} - -QByteArray mtpFileLoader::computeFileReference() const { - if (_location) { - return _location->fileReference(); - } else if (_locationType == SecureFileLocation) { - return QByteArray(); - } - return _fileReference; + placeSentRequest(sendRequest(requestData), requestData); } void mtpFileLoader::requestMoreCdnFileHashes() { @@ -805,10 +758,12 @@ void mtpFileLoader::requestMoreCdnFileHashes() { auto offset = _cdnUncheckedParts.cbegin()->first; auto requestData = RequestData(); - requestData.dcId = _dcId; + requestData.dcId = dcId(); requestData.dcIndex = 0; requestData.offset = offset; - auto shiftedDcId = MTP::downloadDcId(requestData.dcId, requestData.dcIndex); + auto shiftedDcId = MTP::downloadDcId( + requestData.dcId, + requestData.dcIndex); auto requestId = _cdnHashesRequestId = MTP::send( MTPupload_GetCdnFileHashes( MTP_bytes(_cdnToken), @@ -856,7 +811,7 @@ void mtpFileLoader::cdnPartLoaded(const MTPupload_CdnFile &result, mtpRequestId auto offset = finishSentRequestGetOffset(requestId); if (result.type() == mtpc_upload_cdnFileReuploadNeeded) { auto requestData = RequestData(); - requestData.dcId = _dcId; + requestData.dcId = dcId(); requestData.dcIndex = 0; requestData.offset = offset; auto shiftedDcId = MTP::downloadDcId(requestData.dcId, requestData.dcIndex); @@ -1057,10 +1012,10 @@ bool mtpFileLoader::feedPart(int offset, bytes::const_span buffer) { if (_locationType != UnknownFileLocation && !_filename.isEmpty()) { Local::writeFileLocation( - mediaKey(_locationType, _dcId, _id), + mediaKey(_locationType, dcId(), objId()), FileLocation(_filename)); } - if (_urlLocation + if (_location.is() || _locationType == UnknownFileLocation || _toCache == LoadToCacheAsWell) { if (const auto key = cacheKey()) { @@ -1214,16 +1169,15 @@ void mtpFileLoader::changeCDNParams( } std::optional mtpFileLoader::cacheKey() const { - if (_urlLocation) { - return Data::WebDocumentCacheKey(*_urlLocation); - } else if (_geoLocation) { - return Data::GeoPointCacheKey(*_geoLocation); - } else if (_location) { - return Data::StorageCacheKey(*_location); - } else if (_toCache == LoadToCacheAsWell && _id != 0) { - return Data::DocumentCacheKey(_dcId, _id); - } - return std::nullopt; + return _location.match([&](const WebFileLocation &location) { + return std::make_optional(Data::WebDocumentCacheKey(location)); + }, [&](const GeoPointLocation &location) { + return std::make_optional(Data::GeoPointCacheKey(location)); + }, [&](const StorageFileLocation &location) { + return (_toCache == LoadToCacheAsWell) + ? std::make_optional(location.cacheKey()) + : std::nullopt; + }); } mtpFileLoader::~mtpFileLoader() { diff --git a/Telegram/SourceFiles/storage/file_download.h b/Telegram/SourceFiles/storage/file_download.h index a5aea0490..aeee1755b 100644 --- a/Telegram/SourceFiles/storage/file_download.h +++ b/Telegram/SourceFiles/storage/file_download.h @@ -205,17 +205,7 @@ class WebFileLocation; class mtpFileLoader : public FileLoader, public RPCSender { public: mtpFileLoader( - not_null location, - Data::FileOrigin origin, - int32 size, - LoadFromCloudSetting fromCloud, - bool autoLoading, - uint8 cacheTag); - mtpFileLoader( - int32 dc, - uint64 id, - uint64 accessHash, - const QByteArray &fileReference, + const StorageFileLocation &location, Data::FileOrigin origin, LocationType type, const QString &toFile, @@ -225,13 +215,13 @@ public: bool autoLoading, uint8 cacheTag); mtpFileLoader( - const WebFileLocation *location, + const WebFileLocation &location, int32 size, LoadFromCloudSetting fromCloud, bool autoLoading, uint8 cacheTag); mtpFileLoader( - const GeoPointLocation *location, + const GeoPointLocation &location, int32 size, LoadFromCloudSetting fromCloud, bool autoLoading, @@ -240,9 +230,7 @@ public: int32 currentOffset(bool includeSkipped = false) const override; Data::FileOrigin fileOrigin() const override; - uint64 objId() const override { - return _id; - } + uint64 objId() const override; void stop() override { rpcInvalidate(); @@ -269,12 +257,11 @@ private: std::optional cacheKey() const override; void cancelRequests() override; + MTP::DcId dcId() const; int partSize() const; RequestData prepareRequest(int offset) const; void makeRequest(int offset); - [[nodiscard]] MTPInputFileLocation computeLocation() const; - [[nodiscard]] QByteArray computeFileReference() const; bool loadPart() override; void normalPartLoaded(const MTPupload_File &result, mtpRequestId requestId); void webPartLoaded(const MTPupload_WebFile &result, mtpRequestId requestId); @@ -290,6 +277,7 @@ private: bool normalPartFailed(QByteArray fileReference, const RPCError &error, mtpRequestId requestId); bool cdnPartFailed(const RPCError &error, mtpRequestId requestId); + mtpRequestId sendRequest(const RequestData &requestData); void placeSentRequest(mtpRequestId requestId, const RequestData &requestData); int finishSentRequestGetOffset(mtpRequestId requestId); void switchToCDN(int offset, const MTPDupload_fileCdnRedirect &redirect); @@ -309,15 +297,10 @@ private: int32 _skippedBytes = 0; int32 _nextRequestOffset = 0; - MTP::DcId _dcId = 0; // for photo locations - StorageImageLocation *_location = nullptr; - - uint64 _id = 0; // for document locations - uint64 _accessHash = 0; - QByteArray _fileReference; - - const WebFileLocation *_urlLocation = nullptr; // for webdocument locations - const GeoPointLocation *_geoLocation = nullptr; // for webdocument locations + base::variant< + StorageFileLocation, + WebFileLocation, + GeoPointLocation> _location; Data::FileOrigin _origin; diff --git a/Telegram/SourceFiles/ui/image/image.cpp b/Telegram/SourceFiles/ui/image/image.cpp index 2235e733c..fa0f5d1dd 100644 --- a/Telegram/SourceFiles/ui/image/image.cpp +++ b/Telegram/SourceFiles/ui/image/image.cpp @@ -347,7 +347,6 @@ ImagePtr Create(const MTPDwebDocument &document) { auto filesize = 0; // document.vsize.v; return Create( WebFileLocation( - Global::WebFileDcId(), document.vurl.v, document.vaccess_hash.v), size.width(), @@ -375,7 +374,6 @@ ImagePtr Create(const MTPDwebDocument &document, QSize box) { auto filesize = 0; // document.vsize.v; return Create( WebFileLocation( - Global::WebFileDcId(), document.vurl.v, document.vaccess_hash.v), box, diff --git a/Telegram/SourceFiles/ui/image/image_location.cpp b/Telegram/SourceFiles/ui/image/image_location.cpp index ece1038bb..ba79e89d2 100644 --- a/Telegram/SourceFiles/ui/image/image_location.cpp +++ b/Telegram/SourceFiles/ui/image/image_location.cpp @@ -150,6 +150,10 @@ int32 StorageFileLocation::dcId() const { return _dcId; } +uint64 StorageFileLocation::objectId() const { + return _id; +} + MTPInputFileLocation StorageFileLocation::tl(int32 self) const { switch (_type) { case Type::Legacy: diff --git a/Telegram/SourceFiles/ui/image/image_location.h b/Telegram/SourceFiles/ui/image/image_location.h index e092e7fb1..814ff41b2 100644 --- a/Telegram/SourceFiles/ui/image/image_location.h +++ b/Telegram/SourceFiles/ui/image/image_location.h @@ -73,6 +73,7 @@ public: uint64 accessHash) const; [[nodiscard]] int32 dcId() const; + [[nodiscard]] uint64 objectId() const; [[nodiscard]] MTPInputFileLocation tl(int32 self) const; [[nodiscard]] QByteArray serialize() const; @@ -194,16 +195,12 @@ inline bool operator!=( class WebFileLocation { public: WebFileLocation() = default; - WebFileLocation(int32 dc, const QByteArray &url, uint64 accessHash) + WebFileLocation(const QByteArray &url, uint64 accessHash) : _accessHash(accessHash) - , _url(url) - , _dc(dc) { + , _url(url) { } bool isNull() const { - return !_dc; - } - int32 dc() const { - return _dc; + return _url.isEmpty(); } uint64 accessHash() const { return _accessHash; @@ -217,13 +214,11 @@ public: private: uint64 _accessHash = 0; QByteArray _url; - int32 _dc = 0; friend inline bool operator==( const WebFileLocation &a, const WebFileLocation &b) { - return (a._dc == b._dc) - && (a._accessHash == b._accessHash) + return (a._accessHash == b._accessHash) && (a._url == b._url); } @@ -290,7 +285,6 @@ inline InMemoryKey inMemoryKey(const WebFileLocation &location) { bytes::copy( bytes::object_as_span(&result), bytes::make_span(sha).subspan(0, sizeof(result))); - result.first |= (uint64(uint16(location.dc())) << 56); return result; } diff --git a/Telegram/SourceFiles/ui/image/image_source.cpp b/Telegram/SourceFiles/ui/image/image_source.cpp index 8a179d208..758ad07a4 100644 --- a/Telegram/SourceFiles/ui/image/image_source.cpp +++ b/Telegram/SourceFiles/ui/image/image_source.cpp @@ -338,7 +338,7 @@ void RemoteSource::setImageBytes(const QByteArray &bytes) { && !bytes.isEmpty() && bytes.size() <= Storage::kMaxFileInMemory) { Auth().data().cache().putIfEmpty( - Data::StorageCacheKey(location), + location.file().cacheKey(), Storage::Cache::Database::TaggedValue( base::duplicate(bytes), Data::kImageCacheTag)); @@ -473,7 +473,7 @@ const StorageImageLocation &StorageSource::location() { std::optional StorageSource::cacheKey() { return _location.valid() - ? base::make_optional(Data::StorageCacheKey(_location)) + ? base::make_optional(_location.file().cacheKey()) : std::nullopt; } @@ -508,9 +508,12 @@ FileLoader *StorageSource::createLoader( bool autoLoading) { return _location.valid() ? new mtpFileLoader( - &_location, + _location.file(), origin, + UnknownFileLocation, + QString(), _size, + LoadToCacheAsWell, fromCloud, autoLoading, Data::kImageCacheTag) @@ -576,7 +579,7 @@ FileLoader *WebCachedSource::createLoader( return _location.isNull() ? nullptr : new mtpFileLoader( - &_location, + _location, _size, fromCloud, autoLoading, @@ -624,11 +627,11 @@ FileLoader *GeoPointSource::createLoader( LoadFromCloudSetting fromCloud, bool autoLoading) { return new mtpFileLoader( - &_location, - _size, - fromCloud, - autoLoading, - Data::kImageCacheTag); + _location, + _size, + fromCloud, + autoLoading, + Data::kImageCacheTag); } DelayedStorageSource::DelayedStorageSource()