From f4cfbc5ed8a6f73bb7156afb580c1f5f1dfaf3b1 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 3 Nov 2023 16:23:53 +0300 Subject: [PATCH] Improved behavior of show more button in boosts list from boosts info. --- Telegram/Resources/langs/lang.strings | 5 +- .../info/boosts/info_boosts_inner_widget.cpp | 7 +-- .../info_statistics_list_controllers.cpp | 49 +++++++++++-------- 3 files changed, 36 insertions(+), 25 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index cf90704d1..6ecca9459 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -4322,7 +4322,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_boosts_list_title#one" = "{count} booster"; "lng_boosts_list_title#other" = "{count} boosters"; "lng_boosts_list_subtext" = "Your channel is currently boosted by these users."; -"lng_boosts_show_more" = "Show More Boosts"; +"lng_boosts_show_more_boosts#one" = "Show {count} More Boosts"; +"lng_boosts_show_more_boosts#other" = "Show {count} More Boosts"; +"lng_boosts_show_more_gifts#one" = "Show {count} More Boosts"; +"lng_boosts_show_more_gifts#other" = "Show {count} More Boosts"; "lng_boosts_list_status" = "boost expires on {date}"; "lng_boosts_link_title" = "Link for boosting"; "lng_boosts_link_subtext" = "Share this link with your subscribers to get more boosts."; diff --git a/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.cpp b/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.cpp index 36c90fef0..494df7a99 100644 --- a/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.cpp +++ b/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.cpp @@ -67,11 +67,12 @@ void FillOverview( object_ptr(content), st::statisticsLayerMargins); - const auto addPrimary = [&](float64 v) { + const auto addPrimary = [&](float64 v, bool approximately = false) { return Ui::CreateChild( container, (v >= 0) - ? Lang::FormatCountToShort(v).string + ? (approximately && v ? QChar(0x2248) : QChar()) + + Lang::FormatCountToShort(v).string : QString(), st::statisticsOverviewValue); }; @@ -109,7 +110,7 @@ void FillOverview( const auto topLeftLabel = addPrimary(stats.level); - const auto topRightLabel = addPrimary(stats.premiumMemberCount); + const auto topRightLabel = addPrimary(stats.premiumMemberCount, true); const auto bottomLeftLabel = addPrimary(stats.boostCount); const auto bottomRightLabel = addPrimary(std::max( stats.nextLevelBoostCount - stats.boostCount, diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp b/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp index 93b05dc38..6d8c4307e 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp +++ b/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp @@ -574,7 +574,9 @@ public: void loadMoreRows() override; [[nodiscard]] bool skipRequest() const; - void setLimit(int limit); + void requestNext(); + + [[nodiscard]] rpl::producer totalBoostsValue() const; private: void applySlice(const Data::BoostsListSlice &slice); @@ -586,11 +588,11 @@ private: Data::BoostsListSlice _firstSlice; Data::BoostsListSlice::OffsetToken _apiToken; - int _limit = 0; - bool _allLoaded = false; bool _requesting = false; + rpl::variable _totalBoosts; + }; BoostsController::BoostsController(BoostsDescriptor d) @@ -609,8 +611,7 @@ bool BoostsController::skipRequest() const { return _requesting || _allLoaded; } -void BoostsController::setLimit(int limit) { - _limit = limit; +void BoostsController::requestNext() { _requesting = true; _api.requestBoosts(_apiToken, [=](const Data::BoostsListSlice &slice) { _requesting = false; @@ -630,7 +631,9 @@ void BoostsController::applySlice(const Data::BoostsListSlice &slice) { _allLoaded = slice.allLoaded; _apiToken = slice.token; + auto sumFromSlice = 0; for (const auto &item : slice.list) { + sumFromSlice += item.multiplier ? item.multiplier : 1; auto row = [&] { if (item.userId && !item.isUnclaimed) { const auto user = session().data().user(item.userId); @@ -642,6 +645,7 @@ void BoostsController::applySlice(const Data::BoostsListSlice &slice) { delegate()->peerListAppendRow(std::move(row)); } delegate()->peerListRefreshRows(); + _totalBoosts = _totalBoosts.current() + sumFromSlice; } void BoostsController::rowClicked(not_null row) { @@ -651,6 +655,10 @@ void BoostsController::rowClicked(not_null row) { } } +rpl::producer BoostsController::totalBoostsValue() const { + return _totalBoosts.value(); +} + } // namespace void AddPublicForwards( @@ -763,7 +771,6 @@ void AddBoostsList( } PeerListContentDelegateSimple delegate; BoostsController controller; - int limit = Api::Boosts::kFirstSlice; }; auto d = BoostsDescriptor{ firstSlice, boostClickedCallback, peer }; const auto state = container->lifetime().make_state(std::move(d)); @@ -772,35 +779,35 @@ void AddBoostsList( object_ptr(container, &state->controller))); state->controller.setDelegate(&state->delegate); - if (max <= state->limit) { - return; - } const auto wrap = container->add( object_ptr>( container, object_ptr( container, - tr::lng_boosts_show_more(), + (firstSlice.token.gifts + ? tr::lng_boosts_show_more_gifts + : tr::lng_boosts_show_more_boosts)( + lt_count, + state->controller.totalBoostsValue( + ) | rpl::map( + max - rpl::mappers::_1 + ) | tr::to_count()), st::statisticsShowMoreButton)), { 0, -st::settingsButton.padding.top(), 0, 0 }); const auto button = wrap->entity(); AddArrow(button); const auto showMore = [=] { - if (state->controller.skipRequest()) { - return; + if (!state->controller.skipRequest()) { + state->controller.requestNext(); + container->resizeToWidth(container->width()); } - state->limit = std::min(int(max), state->limit + Api::Boosts::kLimit); - state->controller.setLimit(state->limit); - if (state->limit == max) { - wrap->toggle(false, anim::type::instant); - } - container->resizeToWidth(container->width()); }; + wrap->toggleOn( + state->controller.totalBoostsValue( + ) | rpl::map(rpl::mappers::_1 > 0 && rpl::mappers::_1 < max), + anim::type::instant); button->setClickedCallback(showMore); - if (state->limit == max) { - wrap->toggle(false, anim::type::instant); - } } } // namespace Info::Statistics