From bfbdf1b935b803298df02d7972d332d41918f91b Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 16 Aug 2024 14:07:49 +0300 Subject: [PATCH] Removed currency stat from channel earn section when it's not available. --- .../earn/info_channel_earn_list.cpp | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp b/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp index 756fb7229648fa..a48262873313ce 100644 --- a/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp +++ b/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp @@ -386,7 +386,13 @@ void InnerWidget::load() { void InnerWidget::fill() { const auto container = this; - const auto &data = _state.currencyEarn; + const auto channel = _peer->asChannel(); + const auto canViewCurrencyEarn = channel + ? (channel->flags() & ChannelDataFlag::CanViewRevenue) + : true; + const auto &data = canViewCurrencyEarn + ? _state.currencyEarn + : Data::EarnStatistics(); const auto &creditsData = _state.creditsEarn; auto currencyStateValue = rpl::single( @@ -417,7 +423,6 @@ void InnerWidget::fill() { const auto nonInteractive = base::unixtime::now() < kNonInteractivePeriod; const auto session = &_peer->session(); - const auto channel = _peer->asChannel(); const auto withdrawalEnabled = WithdrawalEnabled(session) && !nonInteractive; const auto makeContext = [=](not_null l) { @@ -1486,10 +1491,15 @@ void InnerWidget::fill() { [] {}); } if (!isLocked) { - Api::RestrictSponsored(channel, value, [=](const QString &e) { - toggled->fire(false); - _controller->uiShow()->showToast(e); - }); + const auto weak = Ui::MakeWeak(this); + const auto show = _controller->uiShow(); + const auto failed = [=](const QString &e) { + if (weak.data()) { + toggled->fire(false); + show->showToast(e); + } + }; + Api::RestrictSponsored(channel, value, failed); } }, button->lifetime());