From 60b39c8f7e1a3b7c6cd46f4c591a27ad4da7c5e4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 7 Oct 2019 12:19:04 +0300 Subject: [PATCH] Fix inline result previews. --- .../inline_bot_layout_internal.cpp | 4 +-- .../inline_bots/inline_bot_layout_item.cpp | 7 +++- .../inline_bots/inline_bot_layout_item.h | 2 +- .../inline_bots/inline_bot_result.cpp | 4 +-- .../media/view/media_view_overlay_widget.cpp | 32 ++++++++----------- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp index cacf33239..24a485763 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp @@ -625,7 +625,7 @@ void Photo::prepareThumbnail(QSize size, QSize frame) const { } Video::Video(not_null context, Result *result) : FileBase(context, result) -, _link(getResultContentUrlHandler()) +, _link(getResultPreviewHandler()) , _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) , _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) { if (int duration = content_duration()) { @@ -1057,7 +1057,7 @@ void Contact::prepareThumbnail(int width, int height) const { Article::Article(not_null context, Result *result, bool withThumb) : ItemBase(context, result) , _url(getResultUrlHandler()) -, _link(getResultContentUrlHandler()) +, _link(getResultPreviewHandler()) , _withThumb(withThumb) , _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) , _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) { diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp index 32601d549..4823a58f1 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp @@ -187,11 +187,16 @@ ClickHandlerPtr ItemBase::getResultUrlHandler() const { return ClickHandlerPtr(); } -ClickHandlerPtr ItemBase::getResultContentUrlHandler() const { +ClickHandlerPtr ItemBase::getResultPreviewHandler() const { if (!_result->_content_url.isEmpty()) { return std::make_shared( _result->_content_url, false); + } else if (_result->_document && _result->_document->canBePlayed()) { + return std::make_shared( + _result->_document); + } else if (_result->_photo) { + return std::make_shared(_result->_photo); } return ClickHandlerPtr(); } diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.h b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.h index 106cfb507..b506d6cae 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.h +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.h @@ -103,7 +103,7 @@ protected: int getResultDuration() const; QString getResultUrl() const; ClickHandlerPtr getResultUrlHandler() const; - ClickHandlerPtr getResultContentUrlHandler() const; + ClickHandlerPtr getResultPreviewHandler() const; QString getResultThumbLetter() const; not_null context() const { diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp index 495ee9ed1..0cacca7fa 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp @@ -272,9 +272,9 @@ bool Result::onChoose(Layout::ItemBase *layout) { } else if (_document->loading()) { _document->cancel(); } else { - _document->save( + DocumentSaveClickHandler::Save( Data::FileOriginSavedGifs(), - QString()); + _document); } return false; } diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 99d773f64..9aa9e6cc9 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -2358,25 +2358,19 @@ void OverlayWidget::playbackPauseResume() { Expects(_streamed != nullptr); _streamed->resumeOnCallEnd = false; - if (const auto item = Auth().data().message(_msgid)) { - if (_streamed->player.failed()) { - clearStreaming(); - initStreaming(); - } else if (_streamed->player.finished()) { - _streamingStartPaused = false; - restartAtSeekPosition(0); - } else if (_streamed->player.paused()) { - _streamed->player.resume(); - updatePlaybackState(); - playbackPauseMusic(); - } else { - _streamed->player.pause(); - updatePlaybackState(); - } - } else { + if (_streamed->player.failed()) { clearStreaming(); - updateControls(); - update(); + initStreaming(); + } else if (_streamed->player.finished()) { + _streamingStartPaused = false; + restartAtSeekPosition(0); + } else if (_streamed->player.paused()) { + _streamed->player.resume(); + updatePlaybackState(); + playbackPauseMusic(); + } else { + _streamed->player.pause(); + updatePlaybackState(); } } @@ -3324,7 +3318,7 @@ void OverlayWidget::mousePressEvent(QMouseEvent *e) { void OverlayWidget::mouseDoubleClickEvent(QMouseEvent *e) { updateOver(e->pos()); - if (_over == OverVideo) { + if (_over == OverVideo && _streamed) { playbackToggleFullScreen(); playbackPauseResume(); } else {