From dbb0a5ad288d7121457f98bffd67cf9f44da48ad Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 27 Oct 2024 09:42:03 +0300 Subject: [PATCH] Added ability to open currency earn section for owned bots. --- Telegram/Resources/langs/lang.strings | 3 ++ .../earn/info_channel_earn_list.cpp | 37 ++++++++++++------- .../info/profile/info_profile_actions.cpp | 2 +- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index a21992a28..e500f0cb8 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -5507,6 +5507,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_channel_earn_title" = "Monetization"; "lng_channel_earn_about" = "Telegram shares 50% of the revenue from ads displayed in your channel as rewards. {link}"; +"lng_channel_earn_about_bot" = "Telegram shares 50% of the revenue from ads displayed in your bot. {link}"; "lng_channel_earn_about_link" = "Learn more {emoji}"; "lng_channel_earn_overview_title" = "Rewards overview"; "lng_channel_earn_available" = "Rewards available for collection"; @@ -5539,8 +5540,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_channel_earn_cpm#one" = "{emoji} {count} CPM"; "lng_channel_earn_cpm#other" = "{emoji} {count} CPM"; "lng_channel_earn_learn_title" = "Earn From Your Channel"; +"lng_channel_earn_bot_learn_title" = "Earn From Your Bot"; "lng_channel_earn_learn_in_subtitle" = "Telegram Ads"; "lng_channel_earn_learn_in_about" = "Telegram can display ads in your channel."; +"lng_channel_earn_learn_bot_in_about" = "Telegram can display ads in your bot."; "lng_channel_earn_learn_split_subtitle" = "50:50 revenue split"; "lng_channel_earn_learn_split_about" = "You can receive 50% of the ad revenue as rewards in TON."; "lng_channel_earn_learn_out_subtitle" = "Flexible withdrawals"; 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 91ed54be6..49f4c236c 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 @@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_premium_limits.h" #include "data/data_session.h" #include "data/data_web_page.h" +#include "data/data_user.h" #include "data/stickers/data_custom_emoji.h" #include "history/view/controls/history_view_webpage_processor.h" #include "info/channel_statistics/earn/earn_format.h" @@ -386,6 +387,9 @@ void InnerWidget::load() { void InnerWidget::fill() { const auto container = this; + const auto bot = (peerIsUser(_peer->id) && _peer->asUser()->botInfo) + ? _peer->asUser() + : nullptr; const auto channel = _peer->asChannel(); const auto canViewCurrencyEarn = channel ? (channel->flags() & ChannelDataFlag::CanViewRevenue) @@ -393,7 +397,9 @@ void InnerWidget::fill() { const auto &data = canViewCurrencyEarn ? _state.currencyEarn : Data::EarnStatistics(); - const auto &creditsData = _state.creditsEarn; + const auto &creditsData = bot + ? Data::CreditsEarnStatistics() + : _state.creditsEarn; auto currencyStateValue = rpl::single( data @@ -403,11 +409,12 @@ void InnerWidget::fill() { }) ); - auto creditsStateValue = rpl::single( - creditsData - ) | rpl::then( - _stateUpdated.events() | rpl::map([=] { return _state.creditsEarn; }) - ); + auto creditsStateValue = bot + ? rpl::single(Data::CreditsEarnStatistics()) + : rpl::single(creditsData) | rpl::then( + _stateUpdated.events( + ) | rpl::map([this] { return _state.creditsEarn; }) + ); constexpr auto kMinus = QChar(0x2212); //constexpr auto kApproximately = QChar(0x2248); @@ -419,12 +426,8 @@ void InnerWidget::fill() { return c ? ToUsd(c, creditsMultiplier) : QString(); }; - constexpr auto kNonInteractivePeriod = 1717200000; - const auto nonInteractive = base::unixtime::now() < kNonInteractivePeriod; - const auto session = &_peer->session(); - const auto withdrawalEnabled = WithdrawalEnabled(session) - && !nonInteractive; + const auto withdrawalEnabled = WithdrawalEnabled(session); const auto makeContext = [=](not_null l) { return Core::MarkedTextContext{ .session = session, @@ -520,7 +523,9 @@ void InnerWidget::fill() { content, object_ptr( content, - tr::lng_channel_earn_learn_title(), + bot + ? tr::lng_channel_earn_bot_learn_title() + : tr::lng_channel_earn_learn_title(), st::boxTitle))); Ui::AddSkip(content); Ui::AddSkip(content); @@ -566,7 +571,9 @@ void InnerWidget::fill() { }; addEntry( tr::lng_channel_earn_learn_in_subtitle(), - tr::lng_channel_earn_learn_in_about(), + bot + ? tr::lng_channel_earn_learn_bot_in_about() + : tr::lng_channel_earn_learn_in_about(), st::channelEarnLearnChannelIcon); Ui::AddSkip(content); Ui::AddSkip(content); @@ -662,7 +669,9 @@ void InnerWidget::fill() { st::defaultBoxDividerLabelPadding, RectPart::Top | RectPart::Bottom)); }; - addAboutWithLearn(tr::lng_channel_earn_about); + addAboutWithLearn(bot + ? tr::lng_channel_earn_about_bot + : tr::lng_channel_earn_about); { using Type = Statistic::ChartViewType; Ui::AddSkip(container); diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index ffcab486e..a904703a4 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -1950,7 +1950,7 @@ void ActionsFiller::addCurrencyAction(not_null user) { _wrap, tr::lng_manage_peer_bot_balance_currency(), state->balance.value() | rpl::map(rpl::mappers::_1 > 0), - [=] { controller->showSection(Info::BotEarn::Make(user)); }, + [=] { controller->showSection(Info::ChannelEarn::Make(user)); }, &st::infoIconBotBalance); const auto balance = user->session().credits().balanceCurrency(user->id); if (balance) {