2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 22:55:11 +00:00

Use Storage::Cache::Database for file caching.

This commit is contained in:
John Preston
2018-08-27 14:35:58 +03:00
parent a58c082cfa
commit 2e7f4c2f21
30 changed files with 537 additions and 888 deletions

View File

@@ -111,13 +111,29 @@ void PhotoData::forget() {
ImagePtr PhotoData::makeReplyPreview(Data::FileOrigin origin) {
if (replyPreview->isNull() && !thumb->isNull()) {
if (thumb->loaded()) {
int w = thumb->width(), h = thumb->height();
const auto previewFromImage = [&](const ImagePtr &image) {
if (!image->loaded()) {
image->load(origin);
return ImagePtr();
}
int w = image->width(), h = image->height();
if (w <= 0) w = 1;
if (h <= 0) h = 1;
replyPreview = ImagePtr(w > h ? thumb->pix(origin, w * st::msgReplyBarSize.height() / h, st::msgReplyBarSize.height()) : thumb->pix(origin, st::msgReplyBarSize.height()), "PNG");
return ImagePtr(
(w > h
? image->pix(
origin,
w * st::msgReplyBarSize.height() / h,
st::msgReplyBarSize.height())
: image->pix(origin, st::msgReplyBarSize.height())),
"PNG");
};
if (thumb->toDelayedStorageImage()
&& !full->isNull()
&& !full->toDelayedStorageImage()) {
return previewFromImage(full);
} else {
thumb->load(origin);
return previewFromImage(thumb);
}
}
return replyPreview;
@@ -130,6 +146,21 @@ MTPInputPhoto PhotoData::mtpInput() const {
MTP_bytes(fileReference));
}
void PhotoData::collectLocalData(PhotoData *local) {
if (local == this) return;
const auto copyImage = [](const ImagePtr &src, const ImagePtr &dst) {
if (const auto from = src->cacheKey()) {
if (const auto to = dst->cacheKey()) {
Auth().data().cache().copyIfEmpty(*from, *to);
}
}
};
copyImage(local->thumb, thumb);
copyImage(local->medium, medium);
copyImage(local->full, full);
}
void PhotoOpenClickHandler::onClickImpl() const {
Messenger::Instance().showPhoto(this);
}