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 7068e2b8c5..49a8aa7f33 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -663,6 +663,7 @@ void ComposeControls::setHistory(SetHistoryArgs &&args) { updateControlsGeometry(_wrap->size()); updateControlsVisibility(); updateFieldPlaceholder(); + updateSendAsButton(); //if (!_history) { // return; //} @@ -678,17 +679,6 @@ void ComposeControls::setHistory(SetHistoryArgs &&args) { _wrap.get(), peer->asChannel()); } - if (!session().sendAsPeers().shouldChoose(peer)) { - _sendAs = nullptr; - } else if (!_sendAs) { - _sendAs = std::make_unique( - _wrap.get(), - st::sendAsButton); - Ui::SetupSendAsButton( - _sendAs.get(), - rpl::single(peer.get()), - _window); - } session().local().readDraftsWithCursors(_history); applyDraft(); } @@ -995,6 +985,7 @@ void ComposeControls::init() { initField(); initTabbedSelector(); initSendButton(); + initSendAsButton(); initWriteRestriction(); initVoiceRecordBar(); initKeyHandler(); @@ -1629,6 +1620,17 @@ void ComposeControls::initSendButton() { SendMenu::DefaultScheduleCallback(_wrap.get(), sendMenuType(), send)); } +void ComposeControls::initSendAsButton() { + session().sendAsPeers().updated( + ) | rpl::filter([=](not_null peer) { + return _history && (peer == _history->peer); + }) | rpl::start_with_next([=] { + updateSendAsButton(); + updateControlsVisibility(); + updateControlsGeometry(_wrap->size()); + }, _wrap->lifetime()); +} + void ComposeControls::inlineBotResolveDone( const MTPcontacts_ResolvedPeer &result) { Expects(result.type() == mtpc_contacts_resolvedPeer); @@ -1936,6 +1938,23 @@ void ComposeControls::updateMessagesTTLShown() { } } +void ComposeControls::updateSendAsButton() { + Expects(_history != nullptr); + + const auto peer = _history->peer; + if (!session().sendAsPeers().shouldChoose(peer)) { + _sendAs = nullptr; + } else if (!_sendAs) { + _sendAs = std::make_unique( + _wrap.get(), + st::sendAsButton); + Ui::SetupSendAsButton( + _sendAs.get(), + rpl::single(peer.get()), + _window); + } +} + void ComposeControls::paintBackground(QRect clip) { Painter p(_wrap.get()); 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 8cc73c8bd0..09b498b484 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h @@ -197,6 +197,7 @@ private: void initField(); void initTabbedSelector(); void initSendButton(); + void initSendAsButton(); void initWebpageProcess(); void initWriteRestriction(); void initVoiceRecordBar(); @@ -205,6 +206,7 @@ private: void updateSubmitSettings(); void updateSendButtonType(); void updateMessagesTTLShown(); + void updateSendAsButton(); void updateHeight(); void updateWrappingVisibility(); void updateControlsVisibility();