| 160 | } |
| 161 | |
| 162 | void UpdateCloudFile( |
| 163 | CloudFile &file, |
| 164 | const ImageWithLocation &data, |
| 165 | Storage::Cache::Database &cache, |
| 166 | uint8 cacheTag, |
| 167 | Fn<void(FileOrigin)> restartLoader, |
| 168 | Fn<void(QImage, QByteArray)> usePreloaded) { |
| 169 | if (!data.location.valid()) { |
| 170 | if (data.progressivePartSize && !file.location.valid()) { |
| 171 | file.progressivePartSize = data.progressivePartSize; |
| 172 | } |
| 173 | if (data.location.width() |
| 174 | && data.location.height() |
| 175 | && !file.location.valid() |
| 176 | && !file.location.width()) { |
| 177 | file.location = data.location; |
| 178 | } |
| 179 | return; |
| 180 | } |
| 181 | |
| 182 | const auto needStickerThumbnailUpdate = [&] { |
| 183 | const auto was = std::get_if<StorageFileLocation>( |
| 184 | &file.location.file().data); |
| 185 | const auto now = std::get_if<StorageFileLocation>( |
| 186 | &data.location.file().data); |
| 187 | using Type = StorageFileLocation::Type; |
| 188 | if (!was || !now || was->type() != Type::StickerSetThumb) { |
| 189 | return false; |
| 190 | } |
| 191 | return now->valid() |
| 192 | && (now->type() != Type::StickerSetThumb |
| 193 | || now->cacheKey() != was->cacheKey()); |
| 194 | }; |
| 195 | const auto update = !file.location.valid() |
| 196 | || (data.location.file().cacheKey() |
| 197 | && (!file.location.file().cacheKey() |
| 198 | || (file.location.width() < data.location.width()) |
| 199 | || (file.location.height() < data.location.height()) |
| 200 | || needStickerThumbnailUpdate())); |
| 201 | if (!update) { |
| 202 | return; |
| 203 | } |
| 204 | auto cacheBytes = !data.bytes.isEmpty() |
| 205 | ? data.bytes |
| 206 | : v::is<InMemoryLocation>(file.location.file().data) |
| 207 | ? v::get<InMemoryLocation>(file.location.file().data).bytes |
| 208 | : QByteArray(); |
| 209 | if (!cacheBytes.isEmpty()) { |
| 210 | if (const auto cacheKey = data.location.file().cacheKey()) { |
| 211 | cache.putIfEmpty( |
| 212 | cacheKey, |
| 213 | Storage::Cache::Database::TaggedValue( |
| 214 | std::move(cacheBytes), |
| 215 | cacheTag)); |
| 216 | } |
| 217 | } |
| 218 | file.location = data.location; |
| 219 | file.byteSize = data.bytesCount; |
no test coverage detected