Fix good thumbnail generation in sibling stories.

This commit is contained in:
John Preston 2023-05-31 10:39:45 +04:00
parent d76c80bf0e
commit 1f1e543df7
2 changed files with 38 additions and 22 deletions

View file

@ -75,6 +75,7 @@ public:
private:
void waitForGoodThumbnail();
bool updateAfterGoodCheck();
void createStreamedPlayer();
void streamedFailed();
const not_null<DocumentData*> _video;
@ -148,13 +149,22 @@ QImage Sibling::LoaderVideo::blurred() {
QImage Sibling::LoaderVideo::good() {
if (const auto image = _media->goodThumbnail()) {
return image->original();
} else if (!_video->goodThumbnailChecked()) {
} else if (!_video->goodThumbnailChecked()
&& !_video->goodThumbnailNoData()) {
if (!_checkingGoodInCache) {
waitForGoodThumbnail();
}
} else if (_failed) {
return QImage();
} else if (!_streamed) {
createStreamedPlayer();
} else if (_streamed->ready()) {
return _streamed->info().video.cover;
}
return QImage();
}
void Sibling::LoaderVideo::createStreamedPlayer() {
_streamed = std::make_unique<Streaming::Instance>(
_video,
_origin,
@ -173,11 +183,13 @@ QImage Sibling::LoaderVideo::good() {
_update();
} else if (!_streamed->valid()) {
streamedFailed();
} else if (!_streamed->player().active()
&& !_streamed->player().finished()) {
_streamed->play({
.mode = Streaming::Mode::Video,
});
_streamed->pause();
}
} else if (_streamed->ready()) {
return _streamed->info().video.cover;
}
return QImage();
}
void Sibling::LoaderVideo::streamedFailed() {
@ -204,7 +216,8 @@ void Sibling::LoaderVideo::waitForGoodThumbnail() {
}
bool Sibling::LoaderVideo::updateAfterGoodCheck() {
if (!_video->goodThumbnailChecked()) {
if (!_video->goodThumbnailChecked()
&& !_video->goodThumbnailNoData()) {
return false;
}
_checkingGoodInCache = false;

View file

@ -257,12 +257,15 @@ void Document::validateGoodThumbnail() {
const auto length = bytes.size();
if (!length || length > Storage::kMaxFileInMemory) {
LOG(("App Error: Bad thumbnail data for saving to cache."));
bytes = "(failed)";
bytes = "(failed)"_q;
}
crl::on_main(guard, [=] {
if (const auto active = document->activeMediaView()) {
active->setGoodThumbnail(image);
}
if (bytes != "(failed)"_q) {
document->setGoodThumbnailChecked(true);
}
document->owner().cache().putIfEmpty(
document->goodThumbnailCacheKey(),
Storage::Cache::Database::TaggedValue(