From dd401a063be8e09cd40947a56d432eba288c2efa Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 27 Jan 2021 20:25:45 +0400 Subject: [PATCH] Set preview as cancelled if no preview in editing message. --- .../SourceFiles/history/history_widget.cpp | 20 +++++++++++-------- .../history_view_compose_controls.cpp | 11 ++++++++-- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index bdd9a0e6e3..e46bc467e0 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -1327,7 +1327,7 @@ void HistoryWidget::fieldChanged() { } updateSendButtonType(); - if (showRecordButton()) { + if (!HasSendText(_field)) { _previewCancelled = false; } if (updateCmdStartShown()) { @@ -5682,19 +5682,23 @@ void HistoryWidget::editMessage(not_null item) { editData.text.size(), QFIXED_MAX }; + const auto previewPage = [&]() -> WebPageData* { + if (const auto media = item->media()) { + return media->webpage(); + } + return nullptr; + }(); + const auto previewCancelled = !previewPage; _history->setLocalEditDraft(std::make_unique( editData, item->id, cursor, - false)); + previewCancelled)); applyDraft(); - _previewData = nullptr; - if (const auto media = item->media()) { - if (const auto page = media->webpage()) { - _previewData = page; - updatePreview(); - } + _previewData = previewPage; + if (_previewData) { + updatePreview(); } updateBotKeyboard(); diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index da991c175d..c3d962906e 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -1223,7 +1223,7 @@ void ComposeControls::fieldChanged() { _sendActionUpdates.fire({ Api::SendProgressType::Typing }); } updateSendButtonType(); - if (showRecordButton()) { + if (!HasSendText(_field)) { _previewCancelled = false; } if (updateBotCommandShown()) { @@ -1831,13 +1831,20 @@ void ComposeControls::editMessage(not_null item) { editData.text.size(), QFIXED_MAX }; + const auto previewPage = [&]() -> WebPageData* { + if (const auto media = item->media()) { + return media->webpage(); + } + return nullptr; + }(); + const auto previewCancelled = !previewPage; _history->setDraft( draftKey(DraftType::Edit), std::make_unique( editData, item->id, cursor, - false)); + previewCancelled)); applyDraft(); if (_autocomplete) {