From 8460a625883e190e3a2dd54abc6274544ea5db42 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 28 Nov 2021 16:37:09 +0400 Subject: [PATCH] Don't show "Send As" button when editing a message. Fixes #17302. --- .../SourceFiles/history/history_widget.cpp | 5 ++- .../history_view_compose_controls.cpp | 37 ++++++++++++------- .../controls/history_view_compose_controls.h | 2 +- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 00f8abe5f..9eec7f22a 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -2270,6 +2270,9 @@ void HistoryWidget::registerDraftSource() { void HistoryWidget::setEditMsgId(MsgId msgId) { unregisterDraftSources(); _editMsgId = msgId; + if (_history) { + refreshSendAsToggle(); + } registerDraftSource(); } @@ -2388,7 +2391,7 @@ void HistoryWidget::setupSendAsToggle() { void HistoryWidget::refreshSendAsToggle() { Expects(_peer != nullptr); - if (!session().sendAsPeers().shouldChoose(_peer)) { + if (_editMsgId || !session().sendAsPeers().shouldChoose(_peer)) { _sendAs.destroy(); return; } else if (_sendAs) { 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 735b4dcc7..599a7cfe8 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -1012,6 +1012,10 @@ void ComposeControls::init() { ) | rpl::start_with_next([=](const auto &id) { unregisterDraftSources(); updateSendButtonType(); + if (_history && updateSendAsButton()) { + updateControlsVisibility(); + updateControlsGeometry(_wrap->size()); + } registerDraftSource(); }, _wrap->lifetime()); @@ -1626,9 +1630,10 @@ void ComposeControls::initSendAsButton() { ) | rpl::filter([=](not_null peer) { return _history && (peer == _history->peer); }) | rpl::start_with_next([=] { - updateSendAsButton(); - updateControlsVisibility(); - updateControlsGeometry(_wrap->size()); + if (updateSendAsButton()) { + updateControlsVisibility(); + updateControlsGeometry(_wrap->size()); + } }, _wrap->lifetime()); } @@ -1942,21 +1947,27 @@ void ComposeControls::updateMessagesTTLShown() { } } -void ComposeControls::updateSendAsButton() { +bool ComposeControls::updateSendAsButton() { Expects(_history != nullptr); const auto peer = _history->peer; - if (!session().sendAsPeers().shouldChoose(peer)) { + if (isEditingMessage() || !session().sendAsPeers().shouldChoose(peer)) { + if (!_sendAs) { + return false; + } _sendAs = nullptr; - } else if (!_sendAs) { - _sendAs = std::make_unique( - _wrap.get(), - st::sendAsButton); - Ui::SetupSendAsButton( - _sendAs.get(), - rpl::single(peer.get()), - _window); + return true; + } else if (_sendAs) { + return false; } + _sendAs = std::make_unique( + _wrap.get(), + st::sendAsButton); + Ui::SetupSendAsButton( + _sendAs.get(), + rpl::single(peer.get()), + _window); + return true; } void ComposeControls::paintBackground(QRect clip) { diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h index 09b498b48..1a19acca9 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h @@ -206,7 +206,7 @@ private: void updateSubmitSettings(); void updateSendButtonType(); void updateMessagesTTLShown(); - void updateSendAsButton(); + bool updateSendAsButton(); void updateHeight(); void updateWrappingVisibility(); void updateControlsVisibility();