Fix send as button refresh.

This commit is contained in:
John Preston 2021-11-09 21:31:03 +04:00
parent 17ffebb684
commit 3c040ab5f9
2 changed files with 32 additions and 11 deletions

View File

@ -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<Ui::SendAsButton>(
_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<PeerData*> 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<Ui::SendAsButton>(
_wrap.get(),
st::sendAsButton);
Ui::SetupSendAsButton(
_sendAs.get(),
rpl::single(peer.get()),
_window);
}
}
void ComposeControls::paintBackground(QRect clip) {
Painter p(_wrap.get());

View File

@ -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();