/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "data/data_cloud_file.h" #include "data/data_file_origin.h" #include "storage/cache/storage_cache_database.h" #include "storage/file_download.h" namespace Data { void UpdateCloudFile( CloudFile &file, const ImageWithLocation &data, Storage::Cache::Database &cache, Fn restartLoader, Fn usePreloaded) { if (!data.location.valid()) { return; } const auto update = !file.location.valid() || (data.location.file().cacheKey() && (!file.location.file().cacheKey() || (file.location.width() < data.location.width()) || (file.location.height() < data.location.height()))); if (!update) { return; } const auto cacheBytes = !data.bytes.isEmpty() ? data.bytes : file.location.file().data.is() ? file.location.file().data.get_unchecked().bytes : QByteArray(); if (!cacheBytes.isEmpty()) { if (const auto cacheKey = data.location.file().cacheKey()) { cache.putIfEmpty( cacheKey, Storage::Cache::Database::TaggedValue( base::duplicate(data.bytes), Data::kImageCacheTag)); } } file.location = data.location; file.byteSize = data.bytesCount; if (!data.preloaded.isNull()) { file.loader = nullptr; if (usePreloaded) { usePreloaded(data.preloaded); } } else if (file.loader) { const auto origin = base::take(file.loader)->fileOrigin(); restartLoader(origin); } } } // namespace Data