Fix inline bot video results without documents.

Fixes #8060.
This commit is contained in:
John Preston 2020-06-16 19:54:23 +04:00
parent 99704e973b
commit 1024f38944
2 changed files with 19 additions and 29 deletions

View File

@ -679,8 +679,6 @@ Video::Video(not_null<Context*> context, not_null<Result*> result)
, _link(getResultPreviewHandler()) , _link(getResultPreviewHandler())
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) , _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip)
, _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) { , _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) {
Assert(getResultDocument() != nullptr);
if (int duration = content_duration()) { if (int duration = content_duration()) {
_duration = formatDurationText(duration); _duration = formatDurationText(duration);
_durationWidth = st::normalFont->width(_duration); _durationWidth = st::normalFont->width(_duration);
@ -688,10 +686,12 @@ Video::Video(not_null<Context*> context, not_null<Result*> result)
} }
bool Video::withThumbnail() const { bool Video::withThumbnail() const {
const auto document = getShownDocument(); if (const auto document = getShownDocument()) {
Assert(document != nullptr); if (document->hasThumbnail()) {
return true;
return document->hasThumbnail(); }
}
return hasResultThumb();
} }
void Video::initDimensions() { void Video::initDimensions() {
@ -761,6 +761,7 @@ void Video::paint(Painter &p, const QRect &clip, const PaintContext *context) co
void Video::unloadHeavyPart() { void Video::unloadHeavyPart() {
_documentMedia = nullptr; _documentMedia = nullptr;
ItemBase::unloadHeavyPart();
} }
TextState Video::getState( TextState Video::getState(
@ -776,7 +777,7 @@ TextState Video::getState(
} }
void Video::prepareThumbnail(QSize size) const { void Video::prepareThumbnail(QSize size) const {
const auto document = getShownDocument(); if (const auto document = getShownDocument()) {
if (document->hasThumbnail()) { if (document->hasThumbnail()) {
if (!_documentMedia) { if (!_documentMedia) {
_documentMedia = document->createMediaView(); _documentMedia = document->createMediaView();
@ -786,7 +787,10 @@ void Video::prepareThumbnail(QSize size) const {
return; return;
} }
} }
const auto thumb = _documentMedia->thumbnail(); }
const auto thumb = _documentMedia
? _documentMedia->thumbnail()
: getResultThumb(fileOrigin());
if (!thumb) { if (!thumb) {
return; return;
} }

View File

@ -162,7 +162,6 @@ std::unique_ptr<Result> Result::Create(
} }
} else if (result->_type == Type::Audio } else if (result->_type == Type::Audio
|| result->_type == Type::File || result->_type == Type::File
|| result->_type == Type::Video
|| result->_type == Type::Sticker || result->_type == Type::Sticker
|| result->_type == Type::Gif) { || result->_type == Type::Gif) {
if (!result->_document) { if (!result->_document) {
@ -213,19 +212,6 @@ std::unique_ptr<Result> Result::Create(
qs(r.vmessage()), qs(r.vmessage()),
Api::EntitiesFromMTP(session, r.ventities().value_or_empty()), Api::EntitiesFromMTP(session, r.ventities().value_or_empty()),
r.is_no_webpage()); r.is_no_webpage());
if (result->_type == Type::Photo) {
if (!result->_photo) {
return nullptr;
}
} else if (result->_type == Type::Audio
|| result->_type == Type::File
|| result->_type == Type::Video
|| result->_type == Type::Sticker
|| result->_type == Type::Gif) {
if (!result->_document) {
return nullptr;
}
}
if (const auto markup = r.vreply_markup()) { if (const auto markup = r.vreply_markup()) {
result->_mtpKeyboard = std::make_unique<MTPReplyMarkup>(*markup); result->_mtpKeyboard = std::make_unique<MTPReplyMarkup>(*markup);
} }