mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 23:24:01 +02:00
Support all cases for BoostBox.
This commit is contained in:
parent
01428572b0
commit
7a25d70240
5 changed files with 39 additions and 13 deletions
|
@ -2011,6 +2011,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_boost_channel_title_more" = "Help upgrade channel";
|
"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#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_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_title" = "You boosted {channel}!";
|
||||||
"lng_boost_channel_you_first#one" = "This channel needs **{count}** more boost\nto enable stories.";
|
"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.";
|
"lng_boost_channel_you_first#other" = "This channel needs **{count}** more boosts\nto enable stories.";
|
||||||
|
|
|
@ -17,11 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
namespace Api {
|
namespace Api {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr auto TestApiId = 17349;
|
[[nodiscard]] Websites::Entry ParseEntry(
|
||||||
constexpr auto SnapApiId = 611335;
|
|
||||||
constexpr auto DesktopApiId = 2040;
|
|
||||||
|
|
||||||
Websites::Entry ParseEntry(
|
|
||||||
not_null<Data::Session*> owner,
|
not_null<Data::Session*> owner,
|
||||||
const MTPDwebAuthorization &data) {
|
const MTPDwebAuthorization &data) {
|
||||||
auto result = Websites::Entry{
|
auto result = Websites::Entry{
|
||||||
|
|
|
@ -46,11 +46,34 @@ void BoostBox(
|
||||||
box->setWidth(st::boxWideWidth);
|
box->setWidth(st::boxWideWidth);
|
||||||
box->setStyle(st::boostBox);
|
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 {
|
struct State {
|
||||||
rpl::variable<bool> you = false;
|
rpl::variable<bool> you = false;
|
||||||
bool submitted = 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->addTopButton(st::boxTitleClose, [=] {
|
||||||
box->closeBox();
|
box->closeBox();
|
||||||
});
|
});
|
||||||
|
@ -150,6 +173,8 @@ void BoostBox(
|
||||||
? tr::lng_boost_channel_you_title(
|
? tr::lng_boost_channel_you_title(
|
||||||
lt_channel,
|
lt_channel,
|
||||||
rpl::single(data.name))
|
rpl::single(data.name))
|
||||||
|
: full
|
||||||
|
? tr::lng_boost_channel_title_max()
|
||||||
: !data.boost.level
|
: !data.boost.level
|
||||||
? tr::lng_boost_channel_title_first()
|
? tr::lng_boost_channel_title_first()
|
||||||
: tr::lng_boost_channel_title_more();
|
: tr::lng_boost_channel_title_more();
|
||||||
|
@ -164,8 +189,8 @@ void BoostBox(
|
||||||
lt_count,
|
lt_count,
|
||||||
rpl::single(float64(data.boost.level + 1)),
|
rpl::single(float64(data.boost.level + 1)),
|
||||||
Ui::Text::RichLangValue);
|
Ui::Text::RichLangValue);
|
||||||
return your
|
return (your || full)
|
||||||
? ((left > 0)
|
? ((!full && left > 0)
|
||||||
? (!data.boost.level
|
? (!data.boost.level
|
||||||
? tr::lng_boost_channel_you_first(
|
? tr::lng_boost_channel_you_first(
|
||||||
lt_count,
|
lt_count,
|
||||||
|
@ -216,14 +241,16 @@ void BoostBox(
|
||||||
(st::boxRowPadding
|
(st::boxRowPadding
|
||||||
+ QMargins(0, st::boostTextSkip, 0, st::boostBottomSkip)));
|
+ QMargins(0, st::boostTextSkip, 0, st::boostBottomSkip)));
|
||||||
|
|
||||||
auto submit = state->you.value(
|
auto submit = full
|
||||||
) | rpl::map([](bool mine) {
|
? (tr::lng_box_ok() | rpl::type_erased())
|
||||||
return mine ? tr::lng_box_ok() : tr::lng_boost_channel_button();
|
: state->you.value(
|
||||||
}) | rpl::flatten_latest();
|
) | 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), [=] {
|
const auto button = box->addButton(rpl::duplicate(submit), [=] {
|
||||||
if (state->submitted) {
|
if (state->submitted) {
|
||||||
return;
|
return;
|
||||||
} else if (!state->you.current()) {
|
} else if (!full && !state->you.current()) {
|
||||||
state->submitted = true;
|
state->submitted = true;
|
||||||
boost(crl::guard(box, [=](bool success) {
|
boost(crl::guard(box, [=](bool success) {
|
||||||
state->submitted = false;
|
state->submitted = false;
|
||||||
|
|
|
@ -16,6 +16,7 @@ struct BoostCounters {
|
||||||
int boosts = 0;
|
int boosts = 0;
|
||||||
int thisLevelBoosts = 0;
|
int thisLevelBoosts = 0;
|
||||||
int nextLevelBoosts = 0; // Zero means no next level is available.
|
int nextLevelBoosts = 0; // Zero means no next level is available.
|
||||||
|
bool mine = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BoostBoxData {
|
struct BoostBoxData {
|
||||||
|
|
|
@ -639,6 +639,7 @@ void SessionNavigation::resolveBoostState(not_null<ChannelData*> channel) {
|
||||||
.boosts = data.vboosts().v,
|
.boosts = data.vboosts().v,
|
||||||
.thisLevelBoosts = data.vcurrent_level_boosts().v,
|
.thisLevelBoosts = data.vcurrent_level_boosts().v,
|
||||||
.nextLevelBoosts = next,
|
.nextLevelBoosts = next,
|
||||||
|
.mine = data.is_my_boost(),
|
||||||
},
|
},
|
||||||
}, submit));
|
}, submit));
|
||||||
}).fail([=](const MTP::Error &error) {
|
}).fail([=](const MTP::Error &error) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue