diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp index 5ff510e6e8..23788160b0 100644 --- a/Telegram/SourceFiles/data/data_channel.cpp +++ b/Telegram/SourceFiles/data/data_channel.cpp @@ -7,7 +7,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "data/data_channel.h" +#include "api/api_credits.h" #include "api/api_global_privacy.h" +#include "api/api_statistics.h" #include "data/components/credits.h" #include "data/data_changes.h" #include "data/data_channel_admins.h" @@ -1357,6 +1359,34 @@ void ApplyChannelUpdate( channel->setWallPaper({}); } + if (channel->flags() & Flag::CanViewRevenue) { + const auto id = channel->id; + const auto weak = base::make_weak(&channel->session()); + const auto creditsLoadLifetime = std::make_shared(); + const auto creditsLoad + = creditsLoadLifetime->make_state(channel); + creditsLoad->request({}, [=](Data::CreditsStatusSlice slice) { + if (const auto strong = weak.get()) { + strong->credits().apply(id, slice.balance); + creditsLoadLifetime->destroy(); + } + }); + const auto currencyLoadLifetime = std::make_shared(); + const auto currencyLoad + = currencyLoadLifetime->make_state(channel); + currencyLoad->request( + ) | rpl::start_with_error_done([=](const QString &error) { + currencyLoadLifetime->destroy(); + }, [=] { + if (const auto strong = weak.get()) { + strong->credits().applyCurrency( + id, + currencyLoad->data().currentBalance); + currencyLoadLifetime->destroy(); + } + }, *currencyLoadLifetime); + } + // For clearUpTill() call. channel->owner().sendHistoryChangeNotifications(); } diff --git a/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.cpp b/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.cpp index 0455610fd3..f6ca314bcc 100644 --- a/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.cpp +++ b/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/channel_statistics/earn/earn_icons.h" #include "ui/effects/premium_graphics.h" +#include "ui/text/text_custom_emoji.h" #include "ui/rect.h" #include "styles/style_menu_icons.h" #include "styles/style_widgets.h" @@ -136,4 +137,12 @@ QImage MenuIconCredits() { return image; } +std::unique_ptr MakeCurrencyIconEmoji( + const style::font &font, + const QColor &c) { + return std::make_unique( + IconCurrencyColored(font, c), + u"currency_icon:%1:%2"_q.arg(font->height).arg(c.name())); +} + } // namespace Ui::Earn diff --git a/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.h b/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.h index fbdb8160d5..eb82e11fd5 100644 --- a/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.h +++ b/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.h @@ -7,6 +7,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +namespace Ui::Text { +class CustomEmoji; +} // namespace Ui::Text + namespace Ui::Earn { [[nodiscard]] QImage IconCurrencyColored( @@ -17,4 +21,8 @@ namespace Ui::Earn { [[nodiscard]] QImage MenuIconCurrency(const QSize &size); [[nodiscard]] QImage MenuIconCredits(); +std::unique_ptr MakeCurrencyIconEmoji( + const style::font &font, + const QColor &c); + } // namespace Ui::Earn diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index e86aca0b39..9fa24d4b59 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -70,6 +70,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/boxes/peer_qr_box.h" #include "ui/boxes/report_box_graphics.h" #include "ui/controls/userpic_button.h" +#include "ui/effects/credits_graphics.h" #include "ui/effects/toggle_arrow.h" #include "ui/painter.h" #include "ui/rect.h" @@ -2832,6 +2833,68 @@ object_ptr SetupChannelMembersAndManage( st::menuIconAdmin, st::infoChannelAdminsIconPosition); + if (channel->session().credits().balanceCurrency(channel->id) > 0 + || channel->session().credits().balance(channel->id)) { + const auto balanceWrap = result->entity()->add( + object_ptr>( + result->entity(), + object_ptr(result->entity()))); + balanceWrap->toggle(true, anim::type::instant); + + const auto &st = st::infoSharedMediaButton; + + auto customEmojiFactory = [height = st.style.font->height, + font = st.rightLabel.style.font, + color = st.rightLabel.textFg->c]( + QStringView data, + const Ui::Text::MarkedContext &context + ) -> std::unique_ptr { + return (data == Ui::kCreditsCurrency) + ? Ui::MakeCreditsIconEmoji(height, 1) + : std::make_unique( + Ui::Earn::MakeCurrencyIconEmoji(font, color), + QPoint(0, st::channelEarnCurrencyCommonMargins.top())); + }; + const auto context = Ui::Text::MarkedContext{ + .customEmojiFactory = std::move(customEmojiFactory), + }; + + const auto balance = balanceWrap->entity(); + const auto button = AddActionButton( + balance, + tr::lng_manage_peer_bot_balance(), + rpl::single(true), + [=] { 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)), + st, + tr::lng_manage_peer_bot_balance(), + context); + + object_ptr( + balance, + st::menuIconEarn, + st::infoChannelAdminsIconPosition); + } + if (EditPeerInfoBox::Available(channel)) { const auto sessionController = controller->parentController(); const auto button = AddActionButton( diff --git a/Telegram/SourceFiles/settings/settings_common.cpp b/Telegram/SourceFiles/settings/settings_common.cpp index f7e01594a2..465a70735c 100644 --- a/Telegram/SourceFiles/settings/settings_common.cpp +++ b/Telegram/SourceFiles/settings/settings_common.cpp @@ -130,7 +130,8 @@ void CreateRightLabel( not_null button, v::text::data &&label, const style::SettingsButton &st, - rpl::producer buttonText) { + rpl::producer buttonText, + Ui::Text::MarkedContext context) { const auto name = Ui::CreateChild( button.get(), st.rightLabel); @@ -167,7 +168,7 @@ void CreateRightLabel( - st.padding.right() - st.style.font->width(button) - st::settingsButtonRightSkip; - name->setMarkedText(text); + name->setMarkedText(text, context); name->resizeToNaturalWidth(available); name->moveToRight(st::settingsButtonRightSkip, st.padding.top()); }, name->lifetime()); diff --git a/Telegram/SourceFiles/settings/settings_common.h b/Telegram/SourceFiles/settings/settings_common.h index ce8c648e5a..2c2c31b64b 100644 --- a/Telegram/SourceFiles/settings/settings_common.h +++ b/Telegram/SourceFiles/settings/settings_common.h @@ -180,7 +180,8 @@ void CreateRightLabel( not_null button, v::text::data &&label, const style::SettingsButton &st, - rpl::producer buttonText); + rpl::producer buttonText, + Ui::Text::MarkedContext context = {}); struct DividerWithLottieDescriptor { QString lottie; diff --git a/Telegram/SourceFiles/ui/effects/credits_graphics.cpp b/Telegram/SourceFiles/ui/effects/credits_graphics.cpp index 3ffe154eb7..d7822ee730 100644 --- a/Telegram/SourceFiles/ui/effects/credits_graphics.cpp +++ b/Telegram/SourceFiles/ui/effects/credits_graphics.cpp @@ -43,55 +43,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Ui { namespace { -class CreditsIconEmoji final : public Ui::Text::CustomEmoji { -public: - CreditsIconEmoji(int height, int count); - - int width() override; - QString entityData() override; - - void paint(QPainter &p, const Context &context) override; - void unload() override; - bool ready() override; - bool readyInDefaultState() override; - -private: - const int _height; - const int _count; - QImage _image; - -}; - -CreditsIconEmoji::CreditsIconEmoji(int height, int count) -: _height(height) -, _count(count) -, _image(GenerateStars(height, count)) { -} - -int CreditsIconEmoji::width() { - return _image.width() / style::DevicePixelRatio(); -} - -QString CreditsIconEmoji::entityData() { - return u"credits_icon:%1:%2"_q.arg(_height).arg(_count); -} - -void CreditsIconEmoji::paint(QPainter &p, const Context &context) { - p.drawImage(context.position, _image); -} - -void CreditsIconEmoji::unload() { - _image = QImage(); -} - -bool CreditsIconEmoji::ready() { - return true; -} - -bool CreditsIconEmoji::readyInDefaultState() { - return true; -} - PaintRoundImageCallback MultiThumbnail( PaintRoundImageCallback first, PaintRoundImageCallback second, @@ -735,7 +686,9 @@ QImage CreditsWhiteDoubledIcon(int size, float64 outlineRatio) { std::unique_ptr MakeCreditsIconEmoji( int height, int count) { - return std::make_unique(height, count); + return std::make_unique( + GenerateStars(height, count), + u"credits_icon:%1:%2"_q.arg(height).arg(count)); } } // namespace Ui diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 0afa1babbf..0b324ce83c 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 0afa1babbf74b3602d8a0175830e77b98b5a27d8 +Subproject commit 0b324ce83c219c817fdd3c94a23b55fec6fec637