Improved behavior of show more button in boosts list from boosts info.

This commit is contained in:
23rd 2023-11-03 16:23:53 +03:00 committed by John Preston
parent 336705a503
commit f4cfbc5ed8
3 changed files with 36 additions and 25 deletions

View File

@ -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.";

View File

@ -67,11 +67,12 @@ void FillOverview(
object_ptr<Ui::RpWidget>(content),
st::statisticsLayerMargins);
const auto addPrimary = [&](float64 v) {
const auto addPrimary = [&](float64 v, bool approximately = false) {
return Ui::CreateChild<Ui::FlatLabel>(
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,

View File

@ -574,7 +574,9 @@ public:
void loadMoreRows() override;
[[nodiscard]] bool skipRequest() const;
void setLimit(int limit);
void requestNext();
[[nodiscard]] rpl::producer<int> 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<int> _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<PeerListRow*> row) {
@ -651,6 +655,10 @@ void BoostsController::rowClicked(not_null<PeerListRow*> row) {
}
}
rpl::producer<int> 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<State>(std::move(d));
@ -772,35 +779,35 @@ void AddBoostsList(
object_ptr<PeerListContent>(container, &state->controller)));
state->controller.setDelegate(&state->delegate);
if (max <= state->limit) {
return;
}
const auto wrap = container->add(
object_ptr<Ui::SlideWrap<Ui::SettingsButton>>(
container,
object_ptr<Ui::SettingsButton>(
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