diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index e5bd6baa4..88060ecf4 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -1015,6 +1015,18 @@ void HistoryWidget::refreshJoinChannelText() { } } +void HistoryWidget::refreshGiftToChannelShown() { + if (!_giftToChannelIn || !_giftToChannelOut) { + return; + } + const auto channel = _peer->asChannel(); + const auto shown = channel + && channel->isBroadcast() + && channel->stargiftsAvailable(); + _giftToChannelIn->setVisible(shown); + _giftToChannelOut->setVisible(shown); +} + void HistoryWidget::refreshTopBarActiveChat() { const auto state = computeDialogsEntryState(); _topBar->setActiveChat(state, _history->sendActionPainter()); @@ -2036,17 +2048,22 @@ void HistoryWidget::setupShortcuts() { } void HistoryWidget::setupGiftToChannelButton() { - _giftToChannel = Ui::CreateChild( - _muteUnmute.data(), - st::historyGiftToChannel); - _muteUnmute->widthValue() | rpl::start_with_next([=](int width) { - _giftToChannel->moveToRight(0, 0); - }, _giftToChannel->lifetime()); - _giftToChannel->setClickedCallback([=] { - if (_peer) { - Ui::ShowStarGiftBox(controller(), _peer); - } - }); + const auto setupButton = [=](not_null parent) { + auto *button = Ui::CreateChild( + parent.get(), + st::historyGiftToChannel); + parent->widthValue() | rpl::start_with_next([=](int width) { + button->moveToRight(0, 0); + }, button->lifetime()); + button->setClickedCallback([=] { + if (_peer) { + Ui::ShowStarGiftBox(controller(), _peer); + } + }); + return button; + }; + _giftToChannelIn = setupButton(_muteUnmute); + _giftToChannelOut = setupButton(_joinChannel); } void HistoryWidget::pushReplyReturn(not_null item) { @@ -2409,6 +2426,8 @@ void HistoryWidget::showHistory( ) | rpl::start_with_next([=] { updateControlsGeometry(); }, _contactStatus->bar().lifetime()); + + refreshGiftToChannelShown(); if (const auto user = _peer->asUser()) { _businessBotStatus = std::make_unique( controller(), @@ -2418,8 +2437,6 @@ void HistoryWidget::showHistory( ) | rpl::start_with_next([=] { updateControlsGeometry(); }, _businessBotStatus->bar().lifetime()); - } else if (const auto channel = _peer->asChannel()) { - _giftToChannel->setVisible(channel->stargiftsAvailable()); } orderWidgets(); controller()->tabbedSelector()->setCurrentPeer(_peer); @@ -8372,10 +8389,7 @@ void HistoryWidget::fullInfoUpdated() { if (readyForBotStart && clearMaybeSendStart() && hasNonEmpty) { sendBotStartCommand(); } - - if (const auto channel = _peer->asChannel()) { - _giftToChannel->setVisible(channel->stargiftsAvailable()); - } + refreshGiftToChannelShown(); } if (updateCmdStartShown()) { refresh = true; diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index a3531eac6..46624566e 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -395,6 +395,7 @@ private: void refreshTopBarActiveChat(); void refreshJoinChannelText(); + void refreshGiftToChannelShown(); void requestMessageData(MsgId msgId); void messageDataReceived(not_null peer, MsgId msgId); @@ -774,7 +775,8 @@ private: object_ptr _botStart; object_ptr _joinChannel; object_ptr _muteUnmute; - QPointer _giftToChannel; + QPointer _giftToChannelIn; + QPointer _giftToChannelOut; object_ptr _reportMessages; struct { object_ptr button = { nullptr };