From 7a25d702400352a6a8869b4bad75137259450ab3 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 15 Sep 2023 17:37:34 +0400 Subject: [PATCH] Support all cases for BoostBox. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/api/api_websites.cpp | 6 +-- Telegram/SourceFiles/ui/boxes/boost_box.cpp | 43 +++++++++++++++---- Telegram/SourceFiles/ui/boxes/boost_box.h | 1 + .../window/window_session_controller.cpp | 1 + 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 9ae152eae..4091799ae 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -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."; diff --git a/Telegram/SourceFiles/api/api_websites.cpp b/Telegram/SourceFiles/api/api_websites.cpp index 855056675..2ea6b2a09 100644 --- a/Telegram/SourceFiles/api/api_websites.cpp +++ b/Telegram/SourceFiles/api/api_websites.cpp @@ -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 owner, const MTPDwebAuthorization &data) { auto result = Websites::Entry{ diff --git a/Telegram/SourceFiles/ui/boxes/boost_box.cpp b/Telegram/SourceFiles/ui/boxes/boost_box.cpp index dcfa948f2..4e611e635 100644 --- a/Telegram/SourceFiles/ui/boxes/boost_box.cpp +++ b/Telegram/SourceFiles/ui/boxes/boost_box.cpp @@ -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 you = false; bool submitted = false; }; - const auto state = box->lifetime().make_state(); + const auto state = box->lifetime().make_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; diff --git a/Telegram/SourceFiles/ui/boxes/boost_box.h b/Telegram/SourceFiles/ui/boxes/boost_box.h index bd6d1cc84..2036cfb06 100644 --- a/Telegram/SourceFiles/ui/boxes/boost_box.h +++ b/Telegram/SourceFiles/ui/boxes/boost_box.h @@ -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 { diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 714eca63b..7f2a4b6f0 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -639,6 +639,7 @@ void SessionNavigation::resolveBoostState(not_null channel) { .boosts = data.vboosts().v, .thisLevelBoosts = data.vcurrent_level_boosts().v, .nextLevelBoosts = next, + .mine = data.is_my_boost(), }, }, submit)); }).fail([=](const MTP::Error &error) {