Added ability to open currency earn section for owned bots.

This commit is contained in:
23rd 2024-10-27 09:42:03 +03:00
parent 24aaed44b9
commit dbb0a5ad28
3 changed files with 27 additions and 15 deletions

View file

@ -5507,6 +5507,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_channel_earn_title" = "Monetization"; "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" = "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_about_link" = "Learn more {emoji}";
"lng_channel_earn_overview_title" = "Rewards overview"; "lng_channel_earn_overview_title" = "Rewards overview";
"lng_channel_earn_available" = "Rewards available for collection"; "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#one" = "{emoji} {count} CPM";
"lng_channel_earn_cpm#other" = "{emoji} {count} CPM"; "lng_channel_earn_cpm#other" = "{emoji} {count} CPM";
"lng_channel_earn_learn_title" = "Earn From Your Channel"; "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_subtitle" = "Telegram Ads";
"lng_channel_earn_learn_in_about" = "Telegram can display ads in your channel."; "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_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_split_about" = "You can receive 50% of the ad revenue as rewards in TON.";
"lng_channel_earn_learn_out_subtitle" = "Flexible withdrawals"; "lng_channel_earn_learn_out_subtitle" = "Flexible withdrawals";

View file

@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_premium_limits.h" #include "data/data_premium_limits.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_web_page.h" #include "data/data_web_page.h"
#include "data/data_user.h"
#include "data/stickers/data_custom_emoji.h" #include "data/stickers/data_custom_emoji.h"
#include "history/view/controls/history_view_webpage_processor.h" #include "history/view/controls/history_view_webpage_processor.h"
#include "info/channel_statistics/earn/earn_format.h" #include "info/channel_statistics/earn/earn_format.h"
@ -386,6 +387,9 @@ void InnerWidget::load() {
void InnerWidget::fill() { void InnerWidget::fill() {
const auto container = this; const auto container = this;
const auto bot = (peerIsUser(_peer->id) && _peer->asUser()->botInfo)
? _peer->asUser()
: nullptr;
const auto channel = _peer->asChannel(); const auto channel = _peer->asChannel();
const auto canViewCurrencyEarn = channel const auto canViewCurrencyEarn = channel
? (channel->flags() & ChannelDataFlag::CanViewRevenue) ? (channel->flags() & ChannelDataFlag::CanViewRevenue)
@ -393,7 +397,9 @@ void InnerWidget::fill() {
const auto &data = canViewCurrencyEarn const auto &data = canViewCurrencyEarn
? _state.currencyEarn ? _state.currencyEarn
: Data::EarnStatistics(); : Data::EarnStatistics();
const auto &creditsData = _state.creditsEarn; const auto &creditsData = bot
? Data::CreditsEarnStatistics()
: _state.creditsEarn;
auto currencyStateValue = rpl::single( auto currencyStateValue = rpl::single(
data data
@ -403,11 +409,12 @@ void InnerWidget::fill() {
}) })
); );
auto creditsStateValue = rpl::single( auto creditsStateValue = bot
creditsData ? rpl::single(Data::CreditsEarnStatistics())
) | rpl::then( : rpl::single(creditsData) | rpl::then(
_stateUpdated.events() | rpl::map([=] { return _state.creditsEarn; }) _stateUpdated.events(
); ) | rpl::map([this] { return _state.creditsEarn; })
);
constexpr auto kMinus = QChar(0x2212); constexpr auto kMinus = QChar(0x2212);
//constexpr auto kApproximately = QChar(0x2248); //constexpr auto kApproximately = QChar(0x2248);
@ -419,12 +426,8 @@ void InnerWidget::fill() {
return c ? ToUsd(c, creditsMultiplier) : QString(); return c ? ToUsd(c, creditsMultiplier) : QString();
}; };
constexpr auto kNonInteractivePeriod = 1717200000;
const auto nonInteractive = base::unixtime::now() < kNonInteractivePeriod;
const auto session = &_peer->session(); const auto session = &_peer->session();
const auto withdrawalEnabled = WithdrawalEnabled(session) const auto withdrawalEnabled = WithdrawalEnabled(session);
&& !nonInteractive;
const auto makeContext = [=](not_null<Ui::FlatLabel*> l) { const auto makeContext = [=](not_null<Ui::FlatLabel*> l) {
return Core::MarkedTextContext{ return Core::MarkedTextContext{
.session = session, .session = session,
@ -520,7 +523,9 @@ void InnerWidget::fill() {
content, content,
object_ptr<Ui::FlatLabel>( object_ptr<Ui::FlatLabel>(
content, content,
tr::lng_channel_earn_learn_title(), bot
? tr::lng_channel_earn_bot_learn_title()
: tr::lng_channel_earn_learn_title(),
st::boxTitle))); st::boxTitle)));
Ui::AddSkip(content); Ui::AddSkip(content);
Ui::AddSkip(content); Ui::AddSkip(content);
@ -566,7 +571,9 @@ void InnerWidget::fill() {
}; };
addEntry( addEntry(
tr::lng_channel_earn_learn_in_subtitle(), 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); st::channelEarnLearnChannelIcon);
Ui::AddSkip(content); Ui::AddSkip(content);
Ui::AddSkip(content); Ui::AddSkip(content);
@ -662,7 +669,9 @@ void InnerWidget::fill() {
st::defaultBoxDividerLabelPadding, st::defaultBoxDividerLabelPadding,
RectPart::Top | RectPart::Bottom)); 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; using Type = Statistic::ChartViewType;
Ui::AddSkip(container); Ui::AddSkip(container);

View file

@ -1950,7 +1950,7 @@ void ActionsFiller::addCurrencyAction(not_null<UserData*> user) {
_wrap, _wrap,
tr::lng_manage_peer_bot_balance_currency(), tr::lng_manage_peer_bot_balance_currency(),
state->balance.value() | rpl::map(rpl::mappers::_1 > 0), state->balance.value() | rpl::map(rpl::mappers::_1 > 0),
[=] { controller->showSection(Info::BotEarn::Make(user)); }, [=] { controller->showSection(Info::ChannelEarn::Make(user)); },
&st::infoIconBotBalance); &st::infoIconBotBalance);
const auto balance = user->session().credits().balanceCurrency(user->id); const auto balance = user->session().credits().balanceCurrency(user->id);
if (balance) { if (balance) {