mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-24 19:27:17 +00:00
The following are commits related to removed variables. apiwrap.cpp e050e27: kSaveDraftBeforeQuitTimeout app.cpp 113f665: serviceImageCacheSize boxes/auto_download_box.cpp a0c6104: checked(Source source, Type type) boxes/background_preview_box.cpp b6edf45: resultBytesPerPixel fe21b5a: ms boxes/calendar_box.cpp ae97704: yearIndex, monthIndex 99bb093: ms boxes/connection_box.cpp f794d8d: ping boxes/dictionaries_manager.cpp 8353867: session boxes/peer_list_box.cpp 2ce2a14: grayedWidth boxes/peers/add_participants_box.cpp 07e010d: chat, channel boxes/self_destruction_box.cpp fe9f02e: count chat_helpers/emoji_suggestions_widget.cpp a12bc60: is(QLatin1String string) chat_helpers/field_autocomplete.cpp 8c7a35c: atwidth, hashwidth chat_helpers/gifs_list_widget.cpp ff65734: inlineItems 3d846fc: newSelected d1687ab: kSaveDraftBeforeQuitTimeout chat_helpers/stickers_dice_pack.cpp c83e297: kZeroDiceDocumentId chat_helpers/stickers_emoji_pack.cpp d298953: length chat_helpers/stickers_list_widget.cpp eb75859: index, x core/crash_reports.cpp 5940ae6: LaunchedDateTimeStr, LaunchedBinaryName data/data_changes.cpp 3c4e959:clearRealtime data/data_cloud_file.cpp 4b354b0: fromCloud, cacheTag data/data_document_media.cpp 7db5359: kMaxVideoFrameArea data/data_messages.cpp 794e315: wasCount data/data_photo_media.cpp e27d2bc: index data/data_wall_paper.cpp b6edf45: resultBytesPerPixel data/data_types.cpp aa8f62d: kWebDocumentCacheTag, kStorageCacheMask history/admin_log/history_admin_log_inner.cpp 794e315: canDelete, canForward history/history_location_manager.cpp 60f45ab: kCoordPrecision 9f90d3a: kMaxHttpRedirects history/history_message.cpp cedf8a6: kPinnedMessageTextLimit history/history_widget.cpp b305924: serviceColor efa5fc4: hasForward 5e7aa4f: kTabbedSelectorToggleTooltipTimeoutMs, kTabbedSelectorToggleTooltipCount history/view/history_view_context_menu.cpp fe1a90b: isVideoLink, isVoiceLink, isAudioLink settings.cpp e2f54eb: defaultRecent settings/settings_folders.cpp e8bf5bb: kRefreshSuggestedTimeout ui/filter_icon_panel.cpp c4a0bc1: kDelayedHideTimeoutMs window/themes/window_theme_preview.cpp ef927c8: mutedCounter ----- Modified variables boxes/stickers_box.cpp 554eb3a: _rows[pressedIndex] -> set data/data_notify_settings.cpp 734c410: muteForSeconds -> muteUntil history/view/history_view_list_widget.cpp 07528be: _items[index] -> view e5f3bed: fromState, tillState history/history.cpp cd3c1c6: kStatusShowClientsideRecordVideo -> kStatusShowClientsideRecordVoice storage/download_manager_mtproto.cpp ae8fb14: _queues[dcId] -> queue storage/localstorage.cpp 357caf8: MTP::Environment::Production -> production
337 lines
7.6 KiB
C++
337 lines
7.6 KiB
C++
/*
|
|
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 "data/data_session.h"
|
|
#include "storage/cache/storage_cache_database.h"
|
|
#include "storage/file_download.h"
|
|
#include "ui/image/image.h"
|
|
#include "main/main_session.h"
|
|
|
|
namespace Data {
|
|
|
|
CloudFile::~CloudFile() {
|
|
// Destroy loader with still alive CloudFile with already zero '.loader'.
|
|
// Otherwise in ~FileLoader it tries to clear file.loader and crashes.
|
|
base::take(loader);
|
|
}
|
|
|
|
void CloudImageView::set(
|
|
not_null<Main::Session*> session,
|
|
QImage image) {
|
|
_image.emplace(std::move(image));
|
|
session->notifyDownloaderTaskFinished();
|
|
}
|
|
|
|
CloudImage::CloudImage() = default;
|
|
|
|
CloudImage::CloudImage(
|
|
not_null<Main::Session*> session,
|
|
const ImageWithLocation &data) {
|
|
update(session, data);
|
|
}
|
|
|
|
Image *CloudImageView::image() {
|
|
return _image ? &*_image : nullptr;
|
|
}
|
|
|
|
void CloudImage::set(
|
|
not_null<Main::Session*> session,
|
|
const ImageWithLocation &data) {
|
|
const auto &was = _file.location.file().data;
|
|
const auto &now = data.location.file().data;
|
|
if (!data.location.valid()) {
|
|
_file.flags |= CloudFile::Flag::Cancelled;
|
|
_file.loader = nullptr;
|
|
_file.location = ImageLocation();
|
|
_file.byteSize = 0;
|
|
_file.flags = CloudFile::Flag();
|
|
_view = std::weak_ptr<CloudImageView>();
|
|
} else if (was != now
|
|
&& (!was.is<InMemoryLocation>() || now.is<InMemoryLocation>())) {
|
|
_file.location = ImageLocation();
|
|
_view = std::weak_ptr<CloudImageView>();
|
|
}
|
|
UpdateCloudFile(
|
|
_file,
|
|
data,
|
|
session->data().cache(),
|
|
kImageCacheTag,
|
|
[=](FileOrigin origin) { load(session, origin); },
|
|
[=](QImage preloaded) {
|
|
if (const auto view = activeView()) {
|
|
view->set(session, data.preloaded);
|
|
}
|
|
});
|
|
}
|
|
|
|
void CloudImage::update(
|
|
not_null<Main::Session*> session,
|
|
const ImageWithLocation &data) {
|
|
UpdateCloudFile(
|
|
_file,
|
|
data,
|
|
session->data().cache(),
|
|
kImageCacheTag,
|
|
[=](FileOrigin origin) { load(session, origin); },
|
|
[=](QImage preloaded) {
|
|
if (const auto view = activeView()) {
|
|
view->set(session, data.preloaded);
|
|
}
|
|
});
|
|
}
|
|
|
|
bool CloudImage::empty() const {
|
|
return !_file.location.valid();
|
|
}
|
|
|
|
bool CloudImage::loading() const {
|
|
return (_file.loader != nullptr);
|
|
}
|
|
|
|
bool CloudImage::failed() const {
|
|
return (_file.flags & CloudFile::Flag::Failed);
|
|
}
|
|
|
|
void CloudImage::load(not_null<Main::Session*> session, FileOrigin origin) {
|
|
const auto autoLoading = false;
|
|
const auto finalCheck = [=] {
|
|
if (const auto active = activeView()) {
|
|
return !active->image();
|
|
}
|
|
return true;
|
|
};
|
|
const auto done = [=](QImage result) {
|
|
if (const auto active = activeView()) {
|
|
active->set(session, std::move(result));
|
|
}
|
|
};
|
|
LoadCloudFile(
|
|
session,
|
|
_file,
|
|
origin,
|
|
LoadFromCloudOrLocal,
|
|
autoLoading,
|
|
kImageCacheTag,
|
|
finalCheck,
|
|
done);
|
|
}
|
|
|
|
const ImageLocation &CloudImage::location() const {
|
|
return _file.location;
|
|
}
|
|
|
|
int CloudImage::byteSize() const {
|
|
return _file.byteSize;
|
|
}
|
|
|
|
std::shared_ptr<CloudImageView> CloudImage::createView() {
|
|
if (auto active = activeView()) {
|
|
return active;
|
|
}
|
|
auto view = std::make_shared<CloudImageView>();
|
|
_view = view;
|
|
return view;
|
|
}
|
|
|
|
std::shared_ptr<CloudImageView> CloudImage::activeView() {
|
|
return _view.lock();
|
|
}
|
|
|
|
bool CloudImage::isCurrentView(
|
|
const std::shared_ptr<CloudImageView> &view) const {
|
|
if (!view) {
|
|
return empty();
|
|
}
|
|
return !view.owner_before(_view) && !_view.owner_before(view);
|
|
}
|
|
|
|
void UpdateCloudFile(
|
|
CloudFile &file,
|
|
const ImageWithLocation &data,
|
|
Storage::Cache::Database &cache,
|
|
uint8 cacheTag,
|
|
Fn<void(FileOrigin)> restartLoader,
|
|
Fn<void(QImage)> 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;
|
|
}
|
|
auto cacheBytes = !data.bytes.isEmpty()
|
|
? data.bytes
|
|
: file.location.file().data.is<InMemoryLocation>()
|
|
? file.location.file().data.get_unchecked<InMemoryLocation>().bytes
|
|
: QByteArray();
|
|
if (!cacheBytes.isEmpty()) {
|
|
if (const auto cacheKey = data.location.file().cacheKey()) {
|
|
cache.putIfEmpty(
|
|
cacheKey,
|
|
Storage::Cache::Database::TaggedValue(
|
|
std::move(cacheBytes),
|
|
cacheTag));
|
|
}
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
|
|
void LoadCloudFile(
|
|
not_null<Main::Session*> session,
|
|
CloudFile &file,
|
|
FileOrigin origin,
|
|
LoadFromCloudSetting fromCloud,
|
|
bool autoLoading,
|
|
uint8 cacheTag,
|
|
Fn<bool()> finalCheck,
|
|
Fn<void(CloudFile&)> done,
|
|
Fn<void(bool)> fail,
|
|
Fn<void()> progress) {
|
|
if (file.loader) {
|
|
if (fromCloud == LoadFromCloudOrLocal) {
|
|
file.loader->permitLoadFromCloud();
|
|
}
|
|
return;
|
|
} else if ((file.flags & CloudFile::Flag::Failed)
|
|
|| !file.location.valid()
|
|
|| (finalCheck && !finalCheck())) {
|
|
return;
|
|
}
|
|
file.flags &= ~CloudFile::Flag::Cancelled;
|
|
file.loader = CreateFileLoader(
|
|
session,
|
|
file.location.file(),
|
|
origin,
|
|
QString(),
|
|
file.byteSize,
|
|
UnknownFileLocation,
|
|
LoadToCacheAsWell,
|
|
fromCloud,
|
|
autoLoading,
|
|
cacheTag);
|
|
|
|
const auto finish = [done](CloudFile &file) {
|
|
if (!file.loader || file.loader->cancelled()) {
|
|
file.flags |= CloudFile::Flag::Cancelled;
|
|
} else {
|
|
done(file);
|
|
}
|
|
// NB! file.loader may be in ~FileLoader() already.
|
|
if (const auto loader = base::take(file.loader)) {
|
|
if ((file.flags & CloudFile::Flag::Cancelled)
|
|
&& !loader->cancelled()) {
|
|
loader->cancel();
|
|
}
|
|
}
|
|
};
|
|
|
|
file.loader->updates(
|
|
) | rpl::start_with_next_error_done([=] {
|
|
if (const auto onstack = progress) {
|
|
onstack();
|
|
}
|
|
}, [=, &file](bool started) {
|
|
finish(file);
|
|
file.flags |= CloudFile::Flag::Failed;
|
|
if (const auto onstack = fail) {
|
|
onstack(started);
|
|
}
|
|
}, [=, &file] {
|
|
finish(file);
|
|
}, file.loader->lifetime());
|
|
|
|
file.loader->start();
|
|
}
|
|
|
|
void LoadCloudFile(
|
|
not_null<Main::Session*> session,
|
|
CloudFile &file,
|
|
FileOrigin origin,
|
|
LoadFromCloudSetting fromCloud,
|
|
bool autoLoading,
|
|
uint8 cacheTag,
|
|
Fn<bool()> finalCheck,
|
|
Fn<void(QImage)> done,
|
|
Fn<void(bool)> fail,
|
|
Fn<void()> progress) {
|
|
const auto callback = [=](CloudFile &file) {
|
|
if (auto read = file.loader->imageData(); read.isNull()) {
|
|
file.flags |= CloudFile::Flag::Failed;
|
|
if (const auto onstack = fail) {
|
|
onstack(true);
|
|
}
|
|
} else if (const auto onstack = done) {
|
|
onstack(std::move(read));
|
|
}
|
|
};
|
|
LoadCloudFile(
|
|
session,
|
|
file,
|
|
origin,
|
|
fromCloud,
|
|
autoLoading,
|
|
cacheTag,
|
|
finalCheck,
|
|
callback,
|
|
std::move(fail),
|
|
std::move(progress));
|
|
}
|
|
|
|
void LoadCloudFile(
|
|
not_null<Main::Session*> session,
|
|
CloudFile &file,
|
|
FileOrigin origin,
|
|
LoadFromCloudSetting fromCloud,
|
|
bool autoLoading,
|
|
uint8 cacheTag,
|
|
Fn<bool()> finalCheck,
|
|
Fn<void(QByteArray)> done,
|
|
Fn<void(bool)> fail,
|
|
Fn<void()> progress) {
|
|
const auto callback = [=](CloudFile &file) {
|
|
if (auto bytes = file.loader->bytes(); bytes.isEmpty()) {
|
|
file.flags |= CloudFile::Flag::Failed;
|
|
if (const auto onstack = fail) {
|
|
onstack(true);
|
|
}
|
|
} else if (const auto onstack = done) {
|
|
onstack(std::move(bytes));
|
|
}
|
|
};
|
|
LoadCloudFile(
|
|
session,
|
|
file,
|
|
origin,
|
|
fromCloud,
|
|
autoLoading,
|
|
cacheTag,
|
|
finalCheck,
|
|
callback,
|
|
std::move(fail),
|
|
std::move(progress));
|
|
}
|
|
|
|
} // namespace Data
|