Removed cpm configuration.

This commit is contained in:
23rd 2024-03-26 20:41:07 +03:00 committed by John Preston
parent 508119a127
commit 4e0d770d05
8 changed files with 88 additions and 107 deletions

View file

@ -2475,6 +2475,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_boost_channel_needs_level_reactions#one" = "Your channel needs to reach **Level {count}** to add **{same_count}** custom emoji as a reaction."; "lng_boost_channel_needs_level_reactions#one" = "Your channel needs to reach **Level {count}** to add **{same_count}** custom emoji as a reaction.";
"lng_boost_channel_needs_level_reactions#other" = "Your channel needs to reach **Level {count}** to add **{same_count}** custom emoji as reactions."; "lng_boost_channel_needs_level_reactions#other" = "Your channel needs to reach **Level {count}** to add **{same_count}** custom emoji as reactions.";
"lng_boost_channel_title_cpm" = "Boost Channel";
"lng_boost_channel_needs_level_cpm#one" = "Your channel needs to reach **Level {count}** to switch off ads.";
"lng_boost_channel_needs_level_cpm#other" = "Your channel needs to reach **Level {count}** to switch off ads.";
"lng_boost_group_title_emoji" = "Enable emoji pack"; "lng_boost_group_title_emoji" = "Enable emoji pack";
"lng_boost_group_needs_level_emoji#one" = "Your group needs to reach **Level {count}** to set emoji pack."; "lng_boost_group_needs_level_emoji#one" = "Your group needs to reach **Level {count}** to set emoji pack.";
"lng_boost_group_needs_level_emoji#other" = "Your group needs to reach **Level {count}** to set emoji pack."; "lng_boost_group_needs_level_emoji#other" = "Your group needs to reach **Level {count}** to set emoji pack.";

View file

@ -779,7 +779,7 @@ rpl::producer<rpl::no_value, QString> EarnStatistics::request() {
).done([=](const MTPmessages_ChatFull &result) { ).done([=](const MTPmessages_ChatFull &result) {
result.data().vfull_chat().match([&]( result.data().vfull_chat().match([&](
const MTPDchannelFull &d) { const MTPDchannelFull &d) {
_data.minCpm = d.vsponsored_min_cpm().value_or(-1); _data.switchedOff = d.is_restricted_sponsored();
}, [](const auto &) { }, [](const auto &) {
}); });
consumer.put_done(); consumer.put_done();

View file

@ -62,7 +62,7 @@ struct EarnStatistics final {
EarnInt availableBalance = 0; EarnInt availableBalance = 0;
EarnInt overallRevenue = 0; EarnInt overallRevenue = 0;
float64 usdRate = 0.; float64 usdRate = 0.;
int minCpm = -1; bool switchedOff = false;
EarnHistorySlice firstHistorySlice; EarnHistorySlice firstHistorySlice;
}; };

View file

@ -566,3 +566,21 @@ SponsoredMessages::State SponsoredMessages::state(
} }
} // namespace Data } // namespace Data
namespace Api {
void RestrictSponsored(
not_null<ChannelData*> channel,
bool restricted,
Fn<void(QString)> failed) {
channel->session().api().request(MTPchannels_RestrictSponsoredMessages(
channel->inputChannel,
MTP_bool(restricted))
).done([=](const MTPUpdates &updates) {
channel->session().api().applyUpdates(updates);
}).fail([=](const MTP::Error &error) {
failed(error.type());
}).send();
}
} // namespace Api

View file

@ -158,3 +158,13 @@ private:
}; };
} // namespace Data } // namespace Data
namespace Api {
void RestrictSponsored(
not_null<ChannelData*> channel,
bool restricted,
Fn<void(QString)> failed);
} // namespace Api

View file

@ -13,9 +13,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/peers/edit_peer_color_box.h" // AddLevelBadge. #include "boxes/peers/edit_peer_color_box.h" // AddLevelBadge.
#include "chat_helpers/stickers_emoji_pack.h" #include "chat_helpers/stickers_emoji_pack.h"
#include "core/ui_integration.h" // Core::MarkedTextContext. #include "core/ui_integration.h" // Core::MarkedTextContext.
#include "data/data_channel.h"
#include "data/data_peer.h" #include "data/data_peer.h"
#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_sponsored_messages.h"
#include "data/stickers/data_custom_emoji.h" #include "data/stickers/data_custom_emoji.h"
#include "info/channel_statistics/earn/info_earn_widget.h" #include "info/channel_statistics/earn/info_earn_widget.h"
#include "info/info_controller.h" #include "info/info_controller.h"
@ -24,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "statistics/chart_widget.h" #include "statistics/chart_widget.h"
#include "ui/boxes/boost_box.h"
#include "ui/controls/userpic_button.h" #include "ui/controls/userpic_button.h"
#include "ui/effects/animation_value_f.h" #include "ui/effects/animation_value_f.h"
#include "ui/effects/fade_animation.h" #include "ui/effects/fade_animation.h"
@ -822,121 +825,56 @@ void InnerWidget::fill() {
Ui::AddSkip(container); Ui::AddSkip(container);
if (const auto channel = _peer->asChannel()) { if (const auto channel = _peer->asChannel()) {
constexpr auto kMaxCPM = 50; // Debug. constexpr auto kMaxCPM = 50; // Debug.
const auto requiredLevel = Data::LevelLimits(session)
.channelRestrictSponsoredLevelMin();
const auto &phrase = tr::lng_channel_earn_off; const auto &phrase = tr::lng_channel_earn_off;
const auto button = container->add(object_ptr<Ui::SettingsButton>( const auto button = container->add(object_ptr<Ui::SettingsButton>(
container, container,
phrase(), phrase(),
st::settingsButtonNoIcon)); st::settingsButtonNoIconLocked));
const auto toggled = lifetime().make_state<rpl::event_stream<bool>>();
const auto isLocked = channel->levelHint() < requiredLevel;
const auto reason = Ui::AskBoostReason{
.data = Ui::AskBoostCpm{ .requiredLevel = requiredLevel },
};
AddLevelBadge( AddLevelBadge(
Data::LevelLimits(session).channelRestrictSponsoredLevelMin(), requiredLevel,
button, button,
nullptr, nullptr,
channel, channel,
QMargins(st::boxRowPadding.left(), 0, 0, 0), QMargins(st::boxRowPadding.left(), 0, 0, 0),
phrase()); phrase());
const auto wrap = container->add( button->toggleOn(rpl::single(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>( data.switchedOff
container, ) | rpl::then(toggled->events()));
object_ptr<Ui::VerticalLayout>(container)), button->setToggleLocked(isLocked);
st::boxRowPadding);
const auto inner = wrap->entity(); button->toggledChanges(
Ui::AddSkip(inner); ) | rpl::start_with_next([=](bool value) {
Ui::AddSkip(inner); if (isLocked && value) {
const auto line = inner->add(object_ptr<Ui::RpWidget>(inner)); toggled->fire(false);
Ui::AddSkip(inner); CheckBoostLevel(
const auto left = Ui::CreateChild<Ui::FlatLabel>( _controller->uiShow(),
line, _peer,
tr::lng_channel_earn_cpm_min(), [=](int level) {
st::defaultFlatLabel); return (level < requiredLevel)
const auto center = Ui::CreateChild<Ui::FlatLabel>( ? std::make_optional(reason)
line, : std::nullopt;
st::defaultFlatLabel); },
const auto fade = lifetime().make_state<Ui::FadeAnimation>(center); [] {});
fade->setUpdatedCallback([=](float64 o) { center->setOpacity(o); });
const auto right = Ui::CreateChild<Ui::FlatLabel>(
line,
st::defaultFlatLabel);
addEmojiToMajor(right, kMaxCPM * Data::kEarnMultiplier);
const auto slider = Ui::CreateChild<Ui::MediaSlider>(
line,
st::settingsScale);
rpl::combine(
line->sizeValue(),
left->sizeValue(),
center->sizeValue(),
right->sizeValue()
) | rpl::start_with_next([=](
const QSize &s,
const QSize &leftSize,
const QSize &centerSize,
const QSize &rightSize) {
const auto sliderHeight = st::settingsScale.seekSize.height();
line->resize(
line->width(),
leftSize.height() + sliderHeight * 2);
{
const auto r = line->rect();
slider->setGeometry(
0,
r.height() - sliderHeight,
r.width(),
sliderHeight);
} }
left->moveToLeft(0, 0); if (!isLocked) {
right->moveToRight(0, 0); Api::RestrictSponsored(channel, value, [=](const QString &e) {
center->moveToLeft((s.width() - centerSize.width()) / 2, 0); toggled->fire(false);
}, line->lifetime()); _controller->uiShow()->showToast(e);
});
const auto updateLabels = [=](int cpm) {
const auto activeColor = st::windowActiveTextFg->c;
left->setTextColorOverride(!cpm
? std::make_optional(activeColor)
: std::nullopt);
if (cpm > 0 && cpm < kMaxCPM) {
center->setMarkedText(
tr::lng_channel_earn_cpm(
tr::now,
lt_count,
cpm,
lt_emoji,
EmojiCurrency(session),
Ui::Text::RichLangValue),
makeContext(center));
fade->fadeIn(st::channelEarnFadeDuration);
} else {
fade->fadeOut(st::channelEarnFadeDuration);
} }
center->setTextColorOverride(activeColor); }, button->lifetime());
right->setTextColorOverride((cpm == kMaxCPM)
? std::make_optional(activeColor)
: std::nullopt);
};
const auto current = std::max(0, data.minCpm);
slider->setPseudoDiscrete(
kMaxCPM + 1,
[=](int index) { return index; },
current,
updateLabels,
updateLabels);
updateLabels(current);
wrap->toggle(false, anim::type::instant);
button->toggleOn(
rpl::single(false) // Debug.
)->toggledChanges(
) | rpl::filter([=](bool toggled) {
return true;
}) | rpl::start_with_next([=](bool toggled) {
wrap->toggle(toggled, anim::type::normal);
}, container->lifetime());
Ui::AddSkip(container); Ui::AddSkip(container);
Ui::AddDividerText(container, tr::lng_channel_earn_off_about()); Ui::AddDividerText(container, tr::lng_channel_earn_off_about());
Ui::ToggleChildrenVisibility(line, true);
} }
Ui::AddSkip(container); Ui::AddSkip(container);

View file

@ -678,17 +678,18 @@ void AskBoostBox(
box->addTopButton(st::boxTitleClose, [=] { box->closeBox(); }); box->addTopButton(st::boxTitleClose, [=] { box->closeBox(); });
auto title = v::match(data.reason.data, [&]( auto title = v::match(data.reason.data, [](AskBoostChannelColor) {
AskBoostChannelColor data) {
return tr::lng_boost_channel_title_color(); return tr::lng_boost_channel_title_color();
}, [&](AskBoostWallpaper data) { }, [](AskBoostWallpaper) {
return tr::lng_boost_channel_title_wallpaper(); return tr::lng_boost_channel_title_wallpaper();
}, [&](AskBoostEmojiStatus data) { }, [](AskBoostEmojiStatus) {
return tr::lng_boost_channel_title_status(); return tr::lng_boost_channel_title_status();
}, [&](AskBoostEmojiPack data) { }, [](AskBoostEmojiPack) {
return tr::lng_boost_group_title_emoji(); return tr::lng_boost_group_title_emoji();
}, [&](AskBoostCustomReactions data) { }, [](AskBoostCustomReactions) {
return tr::lng_boost_channel_title_reactions(); return tr::lng_boost_channel_title_reactions();
}, [](AskBoostCpm) {
return tr::lng_boost_channel_title_cpm();
}); });
auto reasonText = v::match(data.reason.data, [&]( auto reasonText = v::match(data.reason.data, [&](
AskBoostChannelColor data) { AskBoostChannelColor data) {
@ -722,6 +723,11 @@ void AskBoostBox(
lt_same_count, lt_same_count,
rpl::single(TextWithEntities{ QString::number(data.count) }), rpl::single(TextWithEntities{ QString::number(data.count) }),
Ui::Text::RichLangValue); Ui::Text::RichLangValue);
}, [&](AskBoostCpm data) {
return tr::lng_boost_channel_needs_level_cpm(
lt_count,
rpl::single(float64(data.requiredLevel)),
Ui::Text::RichLangValue);
}); });
auto text = rpl::combine( auto text = rpl::combine(
std::move(reasonText), std::move(reasonText),

View file

@ -89,13 +89,18 @@ struct AskBoostCustomReactions {
int count = 0; int count = 0;
}; };
struct AskBoostCpm {
int requiredLevel = 0;
};
struct AskBoostReason { struct AskBoostReason {
std::variant< std::variant<
AskBoostChannelColor, AskBoostChannelColor,
AskBoostWallpaper, AskBoostWallpaper,
AskBoostEmojiStatus, AskBoostEmojiStatus,
AskBoostEmojiPack, AskBoostEmojiPack,
AskBoostCustomReactions> data; AskBoostCustomReactions,
AskBoostCpm> data;
}; };
struct AskBoostBoxData { struct AskBoostBoxData {