Don't show "Send As" button when editing a message.

Fixes #17302.
This commit is contained in:
John Preston 2021-11-28 16:37:09 +04:00
parent 27e80b8e42
commit 8460a62588
3 changed files with 29 additions and 15 deletions

View file

@ -2270,6 +2270,9 @@ void HistoryWidget::registerDraftSource() {
void HistoryWidget::setEditMsgId(MsgId msgId) { void HistoryWidget::setEditMsgId(MsgId msgId) {
unregisterDraftSources(); unregisterDraftSources();
_editMsgId = msgId; _editMsgId = msgId;
if (_history) {
refreshSendAsToggle();
}
registerDraftSource(); registerDraftSource();
} }
@ -2388,7 +2391,7 @@ void HistoryWidget::setupSendAsToggle() {
void HistoryWidget::refreshSendAsToggle() { void HistoryWidget::refreshSendAsToggle() {
Expects(_peer != nullptr); Expects(_peer != nullptr);
if (!session().sendAsPeers().shouldChoose(_peer)) { if (_editMsgId || !session().sendAsPeers().shouldChoose(_peer)) {
_sendAs.destroy(); _sendAs.destroy();
return; return;
} else if (_sendAs) { } else if (_sendAs) {

View file

@ -1012,6 +1012,10 @@ void ComposeControls::init() {
) | rpl::start_with_next([=](const auto &id) { ) | rpl::start_with_next([=](const auto &id) {
unregisterDraftSources(); unregisterDraftSources();
updateSendButtonType(); updateSendButtonType();
if (_history && updateSendAsButton()) {
updateControlsVisibility();
updateControlsGeometry(_wrap->size());
}
registerDraftSource(); registerDraftSource();
}, _wrap->lifetime()); }, _wrap->lifetime());
@ -1626,9 +1630,10 @@ void ComposeControls::initSendAsButton() {
) | rpl::filter([=](not_null<PeerData*> peer) { ) | rpl::filter([=](not_null<PeerData*> peer) {
return _history && (peer == _history->peer); return _history && (peer == _history->peer);
}) | rpl::start_with_next([=] { }) | rpl::start_with_next([=] {
updateSendAsButton(); if (updateSendAsButton()) {
updateControlsVisibility(); updateControlsVisibility();
updateControlsGeometry(_wrap->size()); updateControlsGeometry(_wrap->size());
}
}, _wrap->lifetime()); }, _wrap->lifetime());
} }
@ -1942,21 +1947,27 @@ void ComposeControls::updateMessagesTTLShown() {
} }
} }
void ComposeControls::updateSendAsButton() { bool ComposeControls::updateSendAsButton() {
Expects(_history != nullptr); Expects(_history != nullptr);
const auto peer = _history->peer; const auto peer = _history->peer;
if (!session().sendAsPeers().shouldChoose(peer)) { if (isEditingMessage() || !session().sendAsPeers().shouldChoose(peer)) {
if (!_sendAs) {
return false;
}
_sendAs = nullptr; _sendAs = nullptr;
} else if (!_sendAs) { return true;
_sendAs = std::make_unique<Ui::SendAsButton>( } else if (_sendAs) {
_wrap.get(), return false;
st::sendAsButton);
Ui::SetupSendAsButton(
_sendAs.get(),
rpl::single(peer.get()),
_window);
} }
_sendAs = std::make_unique<Ui::SendAsButton>(
_wrap.get(),
st::sendAsButton);
Ui::SetupSendAsButton(
_sendAs.get(),
rpl::single(peer.get()),
_window);
return true;
} }
void ComposeControls::paintBackground(QRect clip) { void ComposeControls::paintBackground(QRect clip) {

View file

@ -206,7 +206,7 @@ private:
void updateSubmitSettings(); void updateSubmitSettings();
void updateSendButtonType(); void updateSendButtonType();
void updateMessagesTTLShown(); void updateMessagesTTLShown();
void updateSendAsButton(); bool updateSendAsButton();
void updateHeight(); void updateHeight();
void updateWrappingVisibility(); void updateWrappingVisibility();
void updateControlsVisibility(); void updateControlsVisibility();