Support all cases for BoostBox.

This commit is contained in:
John Preston 2023-09-15 17:37:34 +04:00
parent 01428572b0
commit 7a25d70240
5 changed files with 39 additions and 13 deletions

View File

@ -2011,6 +2011,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_boost_channel_title_more" = "Help upgrade channel";
"lng_boost_channel_needs_more#one" = "{channel} needs **{count}** more boost to be able to {post}.";
"lng_boost_channel_needs_more#other" = "{channel} needs **{count}** more boosts to be able to {post}.";
"lng_boost_channel_title_max" = "Maximum level reached";
"lng_boost_channel_you_title" = "You boosted {channel}!";
"lng_boost_channel_you_first#one" = "This channel needs **{count}** more boost\nto enable stories.";
"lng_boost_channel_you_first#other" = "This channel needs **{count}** more boosts\nto enable stories.";

View File

@ -17,11 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Api {
namespace {
constexpr auto TestApiId = 17349;
constexpr auto SnapApiId = 611335;
constexpr auto DesktopApiId = 2040;
Websites::Entry ParseEntry(
[[nodiscard]] Websites::Entry ParseEntry(
not_null<Data::Session*> owner,
const MTPDwebAuthorization &data) {
auto result = Websites::Entry{

View File

@ -46,11 +46,34 @@ void BoostBox(
box->setWidth(st::boxWideWidth);
box->setStyle(st::boostBox);
const auto full = !data.boost.nextLevelBoosts;
if (data.boost.mine && data.boost.boosts > 0) {
--data.boost.boosts;
}
if (full) {
data.boost.nextLevelBoosts = data.boost.boosts
+ (data.boost.mine ? 1 : 0);
data.boost.thisLevelBoosts = 0;
if (data.boost.level > 0) {
--data.boost.level;
}
} else if (data.boost.mine
&& data.boost.level > 0
&& data.boost.boosts < data.boost.thisLevelBoosts) {
--data.boost.level;
data.boost.nextLevelBoosts = data.boost.thisLevelBoosts;
data.boost.thisLevelBoosts = 0;
}
struct State {
rpl::variable<bool> you = false;
bool submitted = false;
};
const auto state = box->lifetime().make_state<State>();
const auto state = box->lifetime().make_state<State>(State{
.you = data.boost.mine,
});
box->addTopButton(st::boxTitleClose, [=] {
box->closeBox();
});
@ -150,6 +173,8 @@ void BoostBox(
? tr::lng_boost_channel_you_title(
lt_channel,
rpl::single(data.name))
: full
? tr::lng_boost_channel_title_max()
: !data.boost.level
? tr::lng_boost_channel_title_first()
: tr::lng_boost_channel_title_more();
@ -164,8 +189,8 @@ void BoostBox(
lt_count,
rpl::single(float64(data.boost.level + 1)),
Ui::Text::RichLangValue);
return your
? ((left > 0)
return (your || full)
? ((!full && left > 0)
? (!data.boost.level
? tr::lng_boost_channel_you_first(
lt_count,
@ -216,14 +241,16 @@ void BoostBox(
(st::boxRowPadding
+ QMargins(0, st::boostTextSkip, 0, st::boostBottomSkip)));
auto submit = state->you.value(
) | rpl::map([](bool mine) {
return mine ? tr::lng_box_ok() : tr::lng_boost_channel_button();
}) | rpl::flatten_latest();
auto submit = full
? (tr::lng_box_ok() | rpl::type_erased())
: state->you.value(
) | rpl::map([](bool mine) {
return mine ? tr::lng_box_ok() : tr::lng_boost_channel_button();
}) | rpl::flatten_latest();
const auto button = box->addButton(rpl::duplicate(submit), [=] {
if (state->submitted) {
return;
} else if (!state->you.current()) {
} else if (!full && !state->you.current()) {
state->submitted = true;
boost(crl::guard(box, [=](bool success) {
state->submitted = false;

View File

@ -16,6 +16,7 @@ struct BoostCounters {
int boosts = 0;
int thisLevelBoosts = 0;
int nextLevelBoosts = 0; // Zero means no next level is available.
bool mine = false;
};
struct BoostBoxData {

View File

@ -639,6 +639,7 @@ void SessionNavigation::resolveBoostState(not_null<ChannelData*> channel) {
.boosts = data.vboosts().v,
.thisLevelBoosts = data.vcurrent_level_boosts().v,
.nextLevelBoosts = next,
.mine = data.is_my_boost(),
},
}, submit));
}).fail([=](const MTP::Error &error) {