MCPcopy Create free account
hub / github.com/TDesktop-x64/tdesktop / UpdateCloudFile

Function UpdateCloudFile

Telegram/SourceFiles/data/data_cloud_file.cpp:162–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160}
161
162void 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;

Callers 5

setMethod · 0.85
updateMethod · 0.85
updateThumbnailsMethod · 0.85
updateImagesMethod · 0.85
setThumbnailMethod · 0.85

Calls 9

QByteArrayClass · 0.85
validMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45
typeMethod · 0.45
cacheKeyMethod · 0.45
isEmptyMethod · 0.45
isNullMethod · 0.45
fileOriginMethod · 0.45

Tested by

no test coverage detected