Check loaded status through DocumentMedia if possible.

This commit is contained in:
John Preston 2020-04-09 18:02:09 +04:00
parent 669b79588e
commit bf616036b3
25 changed files with 112 additions and 110 deletions

View File

@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_session.h"
#include "data/data_user.h"
#include "data/data_document.h"
#include "data/data_document_media.h"
#include "base/unixtime.h"
#include "boxes/confirm_box.h"
#include "boxes/background_preview_box.h"
@ -410,6 +411,7 @@ BackgroundPreviewBox::BackgroundPreviewBox(
tr::lng_background_text2(tr::now),
true))
, _paper(paper)
, _media(_paper.document() ? _paper.document()->createMediaView() : nullptr)
, _radial([=](crl::time now) { radialAnimationCallback(now); }) {
subscribe(_session->downloaderTaskFinished(), [=] { update(); });
}
@ -710,7 +712,7 @@ void BackgroundPreviewBox::checkLoadedDocument() {
const auto document = _paper.document();
if (!_full.isNull()
|| !document
|| !document->loaded(DocumentData::FilePathResolve::Checked)
|| !_media->loaded(true)
|| _generating) {
return;
}

View File

@ -15,6 +15,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/animations.h"
#include "ui/effects/radial_animation.h"
namespace Data {
class DocumentMedia;
} // namespace Data
namespace Main {
class Session;
} // namespace Main
@ -71,6 +75,7 @@ private:
AdminLog::OwnedItem _text1;
AdminLog::OwnedItem _text2;
Data::WallPaper _paper;
std::shared_ptr<Data::DocumentMedia> _media;
QImage _full;
QPixmap _scaled, _blurred, _fadeOutThumbnail;
Ui::Animations::Simple _fadeIn;

View File

@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_user.h"
#include "data/data_session.h"
#include "data/data_file_origin.h"
#include "data/data_document_media.h"
#include "history/history.h"
#include "history/history_item.h"
#include "lang/lang_keys.h"
@ -157,6 +158,9 @@ EditCaptionBox::EditCaptionBox(
maxW,
maxH);
};
if (doc) {
_gifMedia = doc->createMediaView();
}
prepareGifPreview(doc);
} else {
maxW = dimensions.width();
@ -248,8 +252,13 @@ EditCaptionBox::EditCaptionBox(
_refreshThumbnail();
update();
}
if (doc && doc->isAnimation() && doc->loaded() && !_gifPreview) {
prepareGifPreview(doc);
if (doc && doc->isAnimation()) {
if (!_gifMedia) {
_gifMedia = doc->createMediaView();
}
if (_gifMedia->loaded() && !_gifPreview) {
prepareGifPreview(doc);
}
}
});
@ -306,6 +315,8 @@ void EditCaptionBox::updateEmojiPanelGeometry() {
}
void EditCaptionBox::prepareGifPreview(DocumentData* document) {
Expects(!document || (_gifMedia != nullptr));
const auto isListEmpty = _preparedList.files.empty();
if (_gifPreview) {
return;
@ -315,8 +326,7 @@ void EditCaptionBox::prepareGifPreview(DocumentData* document) {
const auto callback = [=](Media::Clip::Notification notification) {
clipCallback(notification);
};
_gifMedia = document ? document->createMediaView() : nullptr;
if (document && document->isAnimation() && document->loaded()) {
if (document && document->isAnimation() && _gifMedia->loaded()) {
_gifPreview = Media::Clip::MakeReader(
_gifMedia.get(),
_msgId,

View File

@ -628,7 +628,7 @@ void StickerSetBox::Inner::paintSticker(
if (document->sticker()->animated
&& !element.animated
&& document->loaded()) {
&& media->loaded()) {
const_cast<Inner*>(this)->setupLottie(index);
}

View File

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_session.h"
#include "data/data_channel.h"
#include "data/data_file_origin.h"
#include "data/data_document_media.h"
#include "core/application.h"
#include "lang/lang_keys.h"
#include "mainwidget.h"
@ -1913,7 +1914,7 @@ void StickersBox::Inner::readVisibleSets() {
: _rows[i]->sticker->thumbnail();
if (!thumbnail
|| thumbnail->loaded()
|| _rows[i]->sticker->loaded()) {
|| _rows[i]->stickerMedia->loaded()) {
_session->api().readFeaturedSetDelayed(_rows[i]->id);
}
}

View File

@ -643,7 +643,7 @@ void FieldAutocompleteInner::paintEvent(QPaintEvent *e) {
if (document->sticker()->animated
&& !sticker.animated
&& document->loaded()) {
&& media->loaded()) {
setupLottie(sticker);
}

View File

@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_session.h"
#include "data/data_user.h"
#include "data/data_file_origin.h"
#include "data/data_document_media.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/input_fields.h"
#include "ui/effects/ripple_animation.h"
@ -377,7 +378,8 @@ void GifsListWidget::selectInlineResult(int row, int column) {
photo->thumbnail()->loadEvenCancelled(Data::FileOrigin());
}
} else if (const auto document = item->getDocument()) {
if (document->loaded()
const auto media = document->activeMediaView();
if ((media && media->loaded())
|| QGuiApplication::keyboardModifiers() == Qt::ControlModifier) {
_fileChosen.fire_copy(document);
} else if (document->loading()) {

View File

@ -987,7 +987,7 @@ void StickersListWidget::readVisibleFeatured(
for (int j = 0; j < count; ++j) {
if (!set.stickers[j].document->hasThumbnail()
|| set.stickers[j].document->thumbnail()->loaded()
|| set.stickers[j].document->loaded()) {
|| set.stickers[j].documentMedia->loaded()) {
++loaded;
}
}
@ -1718,7 +1718,7 @@ void StickersListWidget::paintSticker(Painter &p, Set &set, int y, int section,
if (document->sticker()->animated
&& !sticker.animated
&& document->loaded()) {
&& media->loaded()) {
setupLottie(set, section, index);
}

View File

@ -300,7 +300,7 @@ void Application::showDocument(not_null<DocumentData*> document, HistoryItem *it
if (cUseExternalVideoPlayer()
&& document->isVideoFile()
&& document->loaded()) {
&& !document->filepath().isEmpty()) {
File::Launch(document->location(false).fname);
} else {
_mediaView->showDocument(document, item);

View File

@ -217,15 +217,15 @@ void CloudThemes::loadDocumentAndInvoke(
Data::FileOriginTheme(cloud.id, cloud.accessHash),
QString());
value.callback = std::move(callback);
if (document->loaded()) {
if (value.documentMedia->loaded()) {
invokeForLoaded(value);
return;
}
if (!alreadyWaiting) {
base::ObservableViewer(
_session->downloaderTaskFinished()
) | rpl::filter([=] {
return document->loaded();
) | rpl::filter([=, &value] {
return value.documentMedia->loaded();
}) | rpl::start_with_next([=, &value] {
invokeForLoaded(value);
}, value.subscription);

View File

@ -48,8 +48,6 @@ namespace {
constexpr auto kMemoryForCache = 128 * 1024 * 1024; // was 32, updated to 128
const auto kAnimatedStickerDimensions = QSize(512, 512);
using FilePathResolve = DocumentData::FilePathResolve;
Core::MediaActiveCache<DocumentData> &ActiveCache() {
static auto Instance = Core::MediaActiveCache<DocumentData>(
kMemoryForCache,
@ -323,7 +321,7 @@ void DocumentOpenClickHandler::Open(
LaunchWithWarning(location.name(), context);
};
const auto &location = data->location(true);
if (data->isTheme() && data->loaded(DocumentData::FilePathResolve::Checked)) {
if (data->isTheme() && data->loaded(true)) {
Core::App().showDocument(data, context);
location.accessDisable();
} else if (data->canBePlayed()) {
@ -364,7 +362,7 @@ void DocumentSaveClickHandler::Save(
if (mode != Mode::ToNewFile && data->saveFromData()) {
return;
}
const auto filepath = data->filepath(FilePathResolve::Checked);
const auto filepath = data->filepath(true);
const auto fileinfo = QFileInfo(
);
const auto filedir = filepath.isEmpty()
@ -416,7 +414,7 @@ void DocumentOpenWithClickHandler::Open(
}
data->saveFromDataSilent();
const auto path = data->filepath(FilePathResolve::Checked);
const auto path = data->filepath(true);
if (!path.isEmpty()) {
File::OpenWith(path, QCursor::pos());
} else {
@ -789,14 +787,14 @@ void DocumentData::automaticLoad(
}
void DocumentData::automaticLoadSettingsChanged() {
if (!cancelled() || status != FileReady || loaded()) {
if (!cancelled() || status != FileReady) {
return;
}
_loader = nullptr;
_flags &= ~Flag::DownloadCancelled;
}
bool DocumentData::loaded(FilePathResolve resolve) const {
bool DocumentData::loaded(bool check) const {
if (loading() && _loader->finished()) {
if (_loader->cancelled()) {
_flags |= Flag::DownloadCancelled;
@ -822,7 +820,7 @@ bool DocumentData::loaded(FilePathResolve resolve) const {
}
_owner->notifyDocumentLayoutChanged(this);
}
return !rawBytes().isEmpty() || !filepath(resolve).isEmpty();
return !rawBytes().isEmpty() || !filepath(check).isEmpty();
}
void DocumentData::destroyLoader() const {
@ -881,7 +879,7 @@ void DocumentData::setLoadedInMediaCache(bool loaded) {
return;
}
_flags = flags;
if (!this->loaded()) {
if (filepath().isEmpty()) {
if (loadedInMediaCache()) {
Local::writeFileLocation(
mediaKey(),
@ -913,7 +911,7 @@ void DocumentData::save(
const QString &toFile,
LoadFromCloudSetting fromCloud,
bool autoLoading) {
if (loaded(FilePathResolve::Checked)) {
if (loaded(true)) {
auto &l = location(true);
if (!toFile.isEmpty()) {
if (!rawBytes().isEmpty()) {
@ -1111,27 +1109,19 @@ void DocumentData::setLocation(const FileLocation &loc) {
}
}
QString DocumentData::filepath(FilePathResolve resolve) const {
const auto check = (resolve != FilePathResolve::Cached);
QString DocumentData::filepath(bool check) const {
return (check && _location.name().isEmpty())
? QString()
: location(check).name();
}
bool DocumentData::saveFromData() {
if (!filepath(FilePathResolve::Checked).isEmpty()) {
return true;
}
return saveFromDataChecked();
return !filepath(true).isEmpty() || saveFromDataChecked();
}
bool DocumentData::saveFromDataSilent() {
if (!filepath(FilePathResolve::Checked).isEmpty()) {
return true;
} else if (Global::AskDownloadPath()) {
return false;
}
return saveFromDataChecked();
return !filepath(true).isEmpty()
|| (!Global::AskDownloadPath() && saveFromDataChecked());
}
bool DocumentData::saveFromDataChecked() {

View File

@ -100,12 +100,7 @@ public:
const HistoryItem *item);
void automaticLoadSettingsChanged();
enum class FilePathResolve {
Cached,
Checked,
};
[[nodiscard]] bool loaded(
FilePathResolve resolve = FilePathResolve::Cached) const;
[[nodiscard]] bool loaded(bool check = false) const;
[[nodiscard]] bool loading() const;
[[nodiscard]] QString loadingFilePath() const;
[[nodiscard]] bool displayLoading() const;
@ -131,8 +126,7 @@ public:
bool saveFromData();
bool saveFromDataSilent();
[[nodiscard]] QString filepath(
FilePathResolve resolve = FilePathResolve::Cached) const;
[[nodiscard]] QString filepath(bool check = false) const;
[[nodiscard]] bool saveToCache() const;

View File

@ -137,7 +137,7 @@ void DocumentMedia::checkStickerLarge() {
}
_owner->automaticLoad(_owner->stickerSetOrigin(), nullptr);
if (data->animated || !_owner->loaded()) {
if (data->animated || !loaded()) {
return;
}
const auto bytes = _owner->rawBytes();
@ -170,6 +170,10 @@ QByteArray DocumentMedia::bytes() const {
return _bytes;
}
bool DocumentMedia::loaded(bool check) const {
return !_bytes.isEmpty() || _owner->loaded(check);// checkLoadedTo(this);
}
void DocumentMedia::checkStickerSmall() {
const auto data = _owner->sticker();
if ((data && data->animated) || _owner->thumbnailEnoughForSticker()) {

View File

@ -34,6 +34,7 @@ public:
void setBytes(const QByteArray &bytes);
[[nodiscard]] QByteArray bytes() const;
[[nodiscard]] bool loaded(bool check = false) const;
// For DocumentData.
static void CheckGoodThumbnail(not_null<DocumentData*> document);

View File

@ -1075,7 +1075,7 @@ void InnerWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
});
}
}
if (!document->filepath(DocumentData::FilePathResolve::Checked).isEmpty()) {
if (!document->filepath(true).isEmpty()) {
_menu->addAction(Platform::IsMac() ? tr::lng_context_show_in_finder(tr::now) : tr::lng_context_show_in_folder(tr::now), [=] {
showContextInFolder(document);
});
@ -1181,8 +1181,7 @@ void InnerWidget::cancelContextDownload(not_null<DocumentData*> document) {
}
void InnerWidget::showContextInFolder(not_null<DocumentData*> document) {
const auto filepath = document->filepath(
DocumentData::FilePathResolve::Checked);
const auto filepath = document->filepath(true);
if (!filepath.isEmpty()) {
File::ShowInFolder(filepath);
}
@ -1691,7 +1690,7 @@ void InnerWidget::performDrag() {
// auto mimeData = std::make_unique<QMimeData>();
// mimeData->setData(forwardMimeType, "1");
// if (auto document = (pressedMedia ? pressedMedia->getDocument() : nullptr)) {
// auto filepath = document->filepath(DocumentData::FilePathResolve::Checked);
// auto filepath = document->filepath(true);
// if (!filepath.isEmpty()) {
// QList<QUrl> urls;
// urls.push_back(QUrl::fromLocalFile(filepath));

View File

@ -1248,8 +1248,7 @@ std::unique_ptr<QMimeData> HistoryInner::prepareDrag() {
result->setData(qsl("application/x-td-forward"), "1");
if (const auto media = view->media()) {
if (const auto document = media->getDocument()) {
const auto filepath = document->filepath(
DocumentData::FilePathResolve::Checked);
const auto filepath = document->filepath(true);
if (!filepath.isEmpty()) {
QList<QUrl> urls;
urls.push_back(QUrl::fromLocalFile(filepath));
@ -1606,7 +1605,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
saveContextGif(itemId);
});
}
if (!document->filepath(DocumentData::FilePathResolve::Checked).isEmpty()) {
if (!document->filepath(true).isEmpty()) {
_menu->addAction(Platform::IsMac() ? tr::lng_context_show_in_finder(tr::now) : tr::lng_context_show_in_folder(tr::now), [=] {
showContextInFolder(document);
});
@ -1886,8 +1885,7 @@ void HistoryInner::cancelContextDownload(not_null<DocumentData*> document) {
}
void HistoryInner::showContextInFolder(not_null<DocumentData*> document) {
const auto filepath = document->filepath(
DocumentData::FilePathResolve::Checked);
const auto filepath = document->filepath(true);
if (!filepath.isEmpty()) {
File::ShowInFolder(filepath);
}

View File

@ -134,8 +134,7 @@ void OpenGif(FullMsgId itemId) {
}
void ShowInFolder(not_null<DocumentData*> document) {
const auto filepath = document->filepath(
DocumentData::FilePathResolve::Checked);
const auto filepath = document->filepath(true);
if (!filepath.isEmpty()) {
File::ShowInFolder(filepath);
}
@ -205,8 +204,7 @@ void AddDocumentActions(
: tr::lng_faved_stickers_add(tr::now)),
[=] { ToggleFavedSticker(document, contextId); });
}
if (!document->filepath(
DocumentData::FilePathResolve::Checked).isEmpty()) {
if (!document->filepath(true).isEmpty()) {
menu->addAction(
(Platform::IsMac()
? tr::lng_context_show_in_finder(tr::now)

View File

@ -2375,8 +2375,7 @@ std::unique_ptr<QMimeData> ListWidget::prepareDrag() {
result->setData(qsl("application/x-td-forward"), "1");
if (const auto media = pressedView->media()) {
if (const auto document = media->getDocument()) {
const auto filepath = document->filepath(
DocumentData::FilePathResolve::Checked);
const auto filepath = document->filepath(true);
if (!filepath.isEmpty()) {
QList<QUrl> urls;
urls.push_back(QUrl::fromLocalFile(filepath));

View File

@ -93,7 +93,7 @@ bool Document::dataFinished() const {
}
bool Document::dataLoaded() const {
return _data->loaded();
return _dataMedia ? _dataMedia->loaded() : _data->loaded();
}
void Document::createComponents(bool caption) {

View File

@ -1270,7 +1270,7 @@ void ListWidget::showContextMenu(
document->cancel();
});
} else {
auto filepath = document->filepath(DocumentData::FilePathResolve::Checked);
auto filepath = document->filepath(true);
if (!filepath.isEmpty()) {
auto handler = App::LambdaDelayed(
st::defaultDropdownMenu.menu.ripple.hideDuration,
@ -1979,7 +1979,7 @@ void ListWidget::performDrag() {
// auto mimeData = std::make_unique<QMimeData>();
// mimeData->setData(forwardMimeType, "1");
// if (auto document = (pressedMedia ? pressedMedia->getDocument() : nullptr)) {
// auto filepath = document->filepath(DocumentData::FilePathResolve::Checked);
// auto filepath = document->filepath(true);
// if (!filepath.isEmpty()) {
// QList<QUrl> urls;
// urls.push_back(QUrl::fromLocalFile(filepath));

View File

@ -535,7 +535,7 @@ void OverlayWidget::documentUpdated(DocumentData *doc) {
update(_docRect);
}
} else if (_streamed) {
const auto ready = _doc->loaded()
const auto ready = _docMedia->loaded()
? _doc->size
: _doc->loading()
? std::clamp(_doc->loadOffset(), 0, _doc->size)
@ -609,7 +609,7 @@ void OverlayWidget::updateControls() {
_docCancel->moveToLeft(_docRect.x() + 2 * st::mediaviewFilePadding + st::mediaviewFileIconSize, _docRect.y() + st::mediaviewFilePadding + st::mediaviewFileLinksTop);
_docCancel->show();
} else {
if (_doc->loaded(DocumentData::FilePathResolve::Checked)) {
if (_docMedia->loaded(true)) {
_docDownload->hide();
_docSaveAs->moveToLeft(_docRect.x() + 2 * st::mediaviewFilePadding + st::mediaviewFileIconSize, _docRect.y() + st::mediaviewFilePadding + st::mediaviewFileLinksTop);
_docSaveAs->show();
@ -634,7 +634,7 @@ void OverlayWidget::updateControls() {
_saveVisible = (_photo && _photo->loaded())
|| (_doc
&& _doc->filepath(DocumentData::FilePathResolve::Checked).isEmpty()
&& _doc->filepath(true).isEmpty()
&& !_doc->loading());
_saveNav = myrtlrect(width() - st::mediaviewIconSize.width() * 3, height() - st::mediaviewIconSize.height(), st::mediaviewIconSize.width(), st::mediaviewIconSize.height());
_saveNavIcon = style::centerrect(_saveNav, st::mediaviewSave);
@ -739,7 +739,7 @@ void OverlayWidget::updateActions() {
if (IsServerMsgId(_msgid.msg)) {
_actions.push_back({ tr::lng_context_to_msg(tr::now), SLOT(onToMessage()) });
}
if (_doc && !_doc->filepath(DocumentData::FilePathResolve::Checked).isEmpty()) {
if (_doc && !_doc->filepath(true).isEmpty()) {
_actions.push_back({ Platform::IsMac() ? tr::lng_context_show_in_finder(tr::now) : tr::lng_context_show_in_folder(tr::now), SLOT(onShowInFolder()) });
}
if ((_doc && documentContentShown()) || (_photo && _photo->loaded())) {
@ -982,7 +982,7 @@ bool OverlayWidget::radialAnimationCallback(crl::time now) {
&& (!anim::Disabled() || updated)) {
update(radialRect());
}
const auto ready = _doc && _doc->loaded();
const auto ready = _doc && _docMedia->loaded();
const auto streamVideo = ready && _doc->canBePlayed();
const auto tryOpenImage = ready && (_doc->size < App::kImageSizeLimit);
if (ready && ((tryOpenImage && !_radial.animating()) || streamVideo)) {
@ -1335,7 +1335,7 @@ void OverlayWidget::onDownload() {
}
location.accessDisable();
} else {
if (_doc->filepath(DocumentData::FilePathResolve::Checked).isEmpty()
if (_doc->filepath(true).isEmpty()
&& !_doc->loading()) {
DocumentSaveClickHandler::Save(
fileOrigin(),
@ -1380,7 +1380,7 @@ void OverlayWidget::onSaveCancel() {
void OverlayWidget::onShowInFolder() {
if (!_doc) return;
auto filepath = _doc->filepath(DocumentData::FilePathResolve::Checked);
auto filepath = _doc->filepath(true);
if (!filepath.isEmpty()) {
File::ShowInFolder(filepath);
close();
@ -2816,7 +2816,7 @@ void OverlayWidget::paintEvent(QPaintEvent *e) {
const auto radialOpacity = radial ? _radial.opacity() : 0.;
if (!_doc || !_doc->hasThumbnail()) {
p.fillRect(_docIconRect, _docIconColor);
if ((!_doc || _doc->loaded()) && (!radial || radialOpacity < 1) && _docIcon) {
if ((!_doc || _docMedia->loaded()) && (!radial || radialOpacity < 1) && _docIcon) {
_docIcon->paint(p, _docIconRect.x() + (_docIconRect.width() - _docIcon->width()), _docIconRect.y(), width());
p.setPen(st::mediaviewFileExtFg);
p.setFont(st::mediaviewFileExtFont);
@ -3058,7 +3058,7 @@ void OverlayWidget::paintRadialLoading(
if (!_streamed->instance.waitingShown()) {
return;
}
} else if (!radial && (!_doc || _doc->loaded())) {
} else if (!radial && (!_doc || _docMedia->loaded())) {
return;
}
@ -3125,7 +3125,7 @@ void OverlayWidget::paintRadialLoadingContent(
} else {
const auto o = overLevel(OverIcon);
paintBg(
_doc->loaded() ? radialOpacity : 1.,
_docMedia->loaded() ? radialOpacity : 1.,
anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, o));
const auto icon = [&]() -> const style::icon * {
@ -3237,7 +3237,7 @@ void OverlayWidget::keyPressEvent(QKeyEvent *e) {
} else if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return || e->key() == Qt::Key_Space) {
if (_streamed) {
playbackPauseResume();
} else if (_doc && !_doc->loading() && (documentBubbleShown() || !_doc->loaded())) {
} else if (_doc && !_doc->loading() && (documentBubbleShown() || !_docMedia->loaded())) {
onDocClick();
}
} else if (e->key() == Qt::Key_Left) {
@ -3698,7 +3698,7 @@ void OverlayWidget::updateOver(QPoint pos) {
} else if (documentContentShown() && contentRect().contains(pos)) {
if ((_doc->isVideoFile() || _doc->isVideoMessage()) && _streamed) {
updateOverState(OverVideo);
} else if (!_streamed && !_doc->loaded()) {
} else if (!_streamed && !_docMedia->loaded()) {
updateOverState(OverIcon);
} else if (_over != OverNone) {
updateOverState(OverNone);

View File

@ -443,7 +443,7 @@ void Video::paint(Painter &p, const QRect &clip, TextSelection selection, const
const auto goodLoaded = _dataMedia->goodThumbnail()
&& _dataMedia->goodThumbnail()->loaded();
bool loaded = _data->loaded(), displayLoading = _data->displayLoading();
bool loaded = dataLoaded(), displayLoading = _data->displayLoading();
if (displayLoading) {
ensureRadial();
if (!_radial->animating()) {
@ -560,7 +560,7 @@ bool Video::dataFinished() const {
}
bool Video::dataLoaded() const {
return _data->loaded();
return _dataMedia ? _dataMedia->loaded() : !_data->filepath().isEmpty();
}
bool Video::iconAnimated() const {
@ -573,7 +573,7 @@ TextState Video::getState(
if (hasPoint(point)) {
const auto link = (_data->loading() || _data->uploading())
? _cancell
: (_data->loaded() || _data->canBePlayed())
: (dataLoaded() || _data->canBePlayed())
? _openl
: _savel;
return { parent(), link };
@ -588,7 +588,7 @@ void Video::updateStatusText() {
statusSize = FileStatusSizeFailed;
} else if (_data->uploading()) {
statusSize = _data->uploadingData->offset;
} else if (_data->loaded()) {
} else if (dataLoaded()) {
statusSize = FileStatusSizeLoaded;
} else {
statusSize = FileStatusSizeReady;
@ -642,7 +642,7 @@ void Voice::initDimensions() {
void Voice::paint(Painter &p, const QRect &clip, TextSelection selection, const PaintContext *context) {
bool selected = (selection == FullSelection);
bool loaded = _data->loaded(), displayLoading = _data->displayLoading();
bool loaded = dataLoaded(), displayLoading = _data->displayLoading();
if (displayLoading) {
ensureRadial();
@ -776,7 +776,7 @@ void Voice::paint(Painter &p, const QRect &clip, TextSelection selection, const
TextState Voice::getState(
QPoint point,
StateRequest request) const {
const auto loaded = _data->loaded();
const auto loaded = dataLoaded();
const auto nameleft = _st.songPadding.left()
+ _st.songThumbSize
@ -847,7 +847,7 @@ bool Voice::dataFinished() const {
}
bool Voice::dataLoaded() const {
return _data->loaded();
return _dataMedia ? _dataMedia->loaded() : !_data->filepath().isEmpty();
}
bool Voice::iconAnimated() const {
@ -882,7 +882,7 @@ bool Voice::updateStatusText() {
int32 statusSize = 0, realDuration = 0;
if (_data->status == FileDownloadFailed || _data->status == FileUploadFailed) {
statusSize = FileStatusSizeFailed;
} else if (_data->loaded()) {
} else if (dataLoaded()) {
statusSize = FileStatusSizeLoaded;
} else {
statusSize = FileStatusSizeReady;
@ -964,7 +964,7 @@ void Document::paint(Painter &p, const QRect &clip, TextSelection selection, con
const auto cornerDownload = downloadInCorner();
_data->automaticLoad(parent()->fullId(), parent());
const auto loaded = _data->loaded();
const auto loaded = dataLoaded();
const auto displayLoading = _data->displayLoading();
if (displayLoading) {
@ -1131,7 +1131,7 @@ void Document::paint(Painter &p, const QRect &clip, TextSelection selection, con
}
void Document::drawCornerDownload(Painter &p, bool selected, const PaintContext *context) const {
if (_data->loaded()
if (dataLoaded()
|| _data->loadedInMediaCache()
|| !downloadInCorner()) {
return;
@ -1170,7 +1170,7 @@ TextState Document::cornerDownloadTextState(
StateRequest request) const {
auto result = TextState(parent());
if (!downloadInCorner()
|| _data->loaded()
|| dataLoaded()
|| _data->loadedInMediaCache()) {
return result;
}
@ -1187,7 +1187,7 @@ TextState Document::cornerDownloadTextState(
TextState Document::getState(
QPoint point,
StateRequest request) const {
const auto loaded = _data->loaded();
const auto loaded = dataLoaded();
const auto wthumb = withThumb();
if (_data->isSong()) {
@ -1308,12 +1308,12 @@ bool Document::dataFinished() const {
}
bool Document::dataLoaded() const {
return _data->loaded();
return _dataMedia ? _dataMedia->loaded() : !_data->filepath().isEmpty();
}
bool Document::iconAnimated() const {
return _data->isSong()
|| !_data->loaded()
|| !dataLoaded()
|| (_radial && _radial->animating());
}
@ -1328,13 +1328,14 @@ bool Document::withThumb() const {
bool Document::updateStatusText() {
bool showPause = false;
int32 statusSize = 0, realDuration = 0;
if (_data->status == FileDownloadFailed || _data->status == FileUploadFailed) {
if (_data->status == FileDownloadFailed
|| _data->status == FileUploadFailed) {
statusSize = FileStatusSizeFailed;
} else if (_data->uploading()) {
statusSize = _data->uploadingData->offset;
} else if (_data->loading()) {
statusSize = _data->loadOffset();
} else if (_data->loaded()) {
} else if (dataLoaded()) {
statusSize = FileStatusSizeLoaded;
} else {
statusSize = FileStatusSizeReady;

View File

@ -565,8 +565,8 @@ void CloudList::refreshColors(Element &element) {
document->save(
Data::FileOriginTheme(theme.id, theme.accessHash),
QString());
if (document->loaded()) {
refreshColorsFromDocument(element, document);
if (element.media->loaded()) {
refreshColorsFromDocument(element);
} else {
setWaiting(element, true);
subscribeToDownloadFinished();
@ -636,14 +636,13 @@ bool CloudList::amCreator(const Data::CloudTheme &theme) const {
return (_window->session().userId() == theme.createdBy);
}
void CloudList::refreshColorsFromDocument(
Element &element,
not_null<DocumentData*> document) {
void CloudList::refreshColorsFromDocument(Element &element) {
Expects(element.media != nullptr);
Expects(element.media->loaded());
const auto id = element.id();
const auto path = document->filepath();
const auto data = element.media
? base::take(element.media)->bytes()
: QByteArray();
const auto path = element.media->owner()->filepath();
const auto data = base::take(element.media)->bytes();
crl::async([=, guard = element.generating.make_guard()]() mutable {
crl::on_main(std::move(guard), [
=,
@ -672,12 +671,13 @@ void CloudList::subscribeToDownloadFinished() {
) | rpl::start_with_next([=] {
auto &&waiting = _elements | ranges::view::filter(&Element::waiting);
const auto still = ranges::count_if(waiting, [&](Element &element) {
const auto id = element.theme.documentId;
const auto document = _window->session().data().document(id);
if (!document->loaded()) {
if (!element.media) {
element.waiting = false;
return false;
} else if (!element.media->loaded()) {
return true;
}
refreshColorsFromDocument(element, document);
refreshColorsFromDocument(element);
element.waiting = false;
return false;
});

View File

@ -108,9 +108,7 @@ private:
void insert(int index, const Data::CloudTheme &theme);
void refreshColors(Element &element);
void showMenu(Element &element);
void refreshColorsFromDocument(
Element &element,
not_null<DocumentData*> document);
void refreshColorsFromDocument(Element &element);
void setWaiting(Element &element, bool waiting);
void subscribeToDownloadFinished();
int resizeGetHeight(int newWidth);

View File

@ -244,7 +244,7 @@ QPixmap MediaPreviewWidget::currentImage() const {
if (_document) {
if (const auto sticker = _document->sticker()) {
if (_cacheStatus != CacheLoaded) {
if (sticker->animated && !_lottie && _document->loaded()) {
if (sticker->animated && !_lottie && _documentMedia->loaded()) {
const_cast<MediaPreviewWidget*>(this)->setupLottie();
}
if (_lottie && _lottie->ready()) {
@ -263,7 +263,7 @@ QPixmap MediaPreviewWidget::currentImage() const {
}
} else {
_document->automaticLoad(_origin, nullptr);
if (_document->loaded()) {
if (_documentMedia->loaded()) {
if (!_gif && !_gif.isBad()) {
auto that = const_cast<MediaPreviewWidget*>(this);
that->_gif = Media::Clip::MakeReader(_documentMedia.get(), FullMsgId(), [=](Media::Clip::Notification notification) {