diff --git a/Telegram/SourceFiles/data/components/credits.cpp b/Telegram/SourceFiles/data/components/credits.cpp index a3e57c0d22..5ae899d77e 100644 --- a/Telegram/SourceFiles/data/components/credits.cpp +++ b/Telegram/SourceFiles/data/components/credits.cpp @@ -135,10 +135,17 @@ void Credits::apply(StarsAmount balance) { void Credits::apply(PeerId peerId, StarsAmount balance) { _cachedPeerBalances[peerId] = balance; + _refreshedByPeerId.fire_copy(peerId); } void Credits::applyCurrency(PeerId peerId, uint64 balance) { _cachedPeerCurrencyBalances[peerId] = balance; + _refreshedByPeerId.fire_copy(peerId); +} + +rpl::producer<> Credits::refreshedByPeerId(PeerId peerId) { + return _refreshedByPeerId.events( + ) | rpl::filter(rpl::mappers::_1 == peerId) | rpl::to_empty; } } // namespace Data diff --git a/Telegram/SourceFiles/data/components/credits.h b/Telegram/SourceFiles/data/components/credits.h index 757e494ef0..e2d719091c 100644 --- a/Telegram/SourceFiles/data/components/credits.h +++ b/Telegram/SourceFiles/data/components/credits.h @@ -37,6 +37,8 @@ public: [[nodiscard]] rpl::producer rateValue( not_null ownedBotOrChannel); + [[nodiscard]] rpl::producer<> refreshedByPeerId(PeerId peerId); + void applyCurrency(PeerId peerId, uint64 balance); [[nodiscard]] uint64 balanceCurrency(PeerId peerId) const; @@ -64,6 +66,8 @@ private: crl::time _lastLoaded = 0; float64 _rate = 0.; + rpl::event_stream _refreshedByPeerId; + SingleQueuedInvokation _reload; }; diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp index 52d37ef95f..da93d015b5 100644 --- a/Telegram/SourceFiles/data/data_channel.cpp +++ b/Telegram/SourceFiles/data/data_channel.cpp @@ -1360,7 +1360,8 @@ void ApplyChannelUpdate( channel->setWallPaper({}); } - if (channel->flags() & Flag::CanViewRevenue) { + if ((channel->flags() & Flag::CanViewRevenue) + || (channel->flags() & Flag::CanViewCreditsRevenue)) { static constexpr auto kTimeout = crl::time(60000); const auto id = channel->id; const auto weak = base::make_weak(&channel->session()); diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 9fa24d4b59..61998c8787 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -2833,13 +2833,34 @@ object_ptr SetupChannelMembersAndManage( st::menuIconAdmin, st::infoChannelAdminsIconPosition); - if (channel->session().credits().balanceCurrency(channel->id) > 0 - || channel->session().credits().balance(channel->id)) { + const auto canViewBalance = false + || (channel->flags() & ChannelDataFlag::CanViewRevenue) + || (channel->flags() & ChannelDataFlag::CanViewCreditsRevenue) + || (channel->loadedStatus() != ChannelData::LoadedStatus::Full); + if (canViewBalance) { const auto balanceWrap = result->entity()->add( object_ptr>( result->entity(), object_ptr(result->entity()))); - balanceWrap->toggle(true, anim::type::instant); + auto refreshed = channel->session().credits().refreshedByPeerId( + channel->id); + auto creditsValue = rpl::single( + rpl::empty_value() + ) | rpl::then(rpl::duplicate(refreshed)) | rpl::map([=] { + return channel->session().credits().balance(channel->id).whole(); + }); + auto currencyValue = rpl::single( + rpl::empty_value() + ) | rpl::then(rpl::duplicate(refreshed)) | rpl::map([=] { + return channel->session().credits().balanceCurrency(channel->id); + }); + balanceWrap->toggleOn( + rpl::combine( + rpl::duplicate(creditsValue), + rpl::duplicate(currencyValue) + ) | rpl::map(rpl::mappers::_1 > 0 || rpl::mappers::_2 > 0), + anim::type::normal); + balanceWrap->finishAnimating(); const auto &st = st::infoSharedMediaButton; @@ -2867,24 +2888,27 @@ object_ptr SetupChannelMembersAndManage( [=] { controller->showSection(Info::ChannelEarn::Make(peer)); }, nullptr); - const auto credits = channel->session().credits().balance( - channel->id).whole(); - const auto currency = channel->session().credits().balanceCurrency( - channel->id); - auto creditsText = (credits > 0) - ? Ui::Text::SingleCustomEmoji(Ui::kCreditsCurrency) - .append(QChar(' ')) - .append(QString::number(credits)) - : TextWithEntities(); - auto currencyText = (currency > 0) - ? Ui::Text::SingleCustomEmoji("_") - .append(QChar(' ')) - .append(Info::ChannelEarn::MajorPart(currency)) - .append(Info::ChannelEarn::MinorPart(currency)) - : TextWithEntities(); ::Settings::CreateRightLabel( button->entity(), - currencyText.append(QChar(' ')).append(std::move(creditsText)), + rpl::combine( + std::move(creditsValue), + std::move(currencyValue) + ) | rpl::map([](uint64 credits, uint64 currency) { + auto creditsText = (credits > 0) + ? Ui::Text::SingleCustomEmoji(Ui::kCreditsCurrency) + .append(QChar(' ')) + .append(QString::number(credits)) + : TextWithEntities(); + auto currencyText = (currency > 0) + ? Ui::Text::SingleCustomEmoji("_") + .append(QChar(' ')) + .append(Info::ChannelEarn::MajorPart(currency)) + .append(Info::ChannelEarn::MinorPart(currency)) + : TextWithEntities(); + return currencyText + .append(QChar(' ')) + .append(std::move(creditsText)); + }), st, tr::lng_manage_peer_bot_balance(), context);