Added support of api update to history lists in section of channel earn.

This commit is contained in:
23rd 2024-06-23 06:48:57 +03:00 committed by John Preston
parent b79c306bfe
commit a84ac933dd
2 changed files with 426 additions and 372 deletions

View file

@ -5214,6 +5214,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_channel_earn_chart_revenue" = "Ad revenue";
"lng_channel_earn_chart_overriden_detail_currency" = "Revenue in TON";
"lng_channel_earn_chart_overriden_detail_usd" = "Revenue in USD";
"lng_channel_earn_currency_history" = "TON Transactions";
"lng_channel_earn_credits_history" = "Stars Transactions";
"lng_bot_earn_title" = "Stars Balance";
"lng_bot_earn_chart_revenue" = "Revenue";

View file

@ -697,7 +697,11 @@ void InnerWidget::fill() {
const auto majorLabel = Ui::CreateChild<Ui::FlatLabel>(
line,
st::channelEarnOverviewMajorLabel);
addEmojiToMajor(majorLabel, rpl::duplicate(currencyValue), {}, {});
addEmojiToMajor(
majorLabel,
rpl::duplicate(currencyValue),
{},
{});
const auto minorLabel = Ui::CreateChild<Ui::FlatLabel>(
line,
rpl::duplicate(currencyValue) | rpl::map(MinorPart),
@ -912,21 +916,27 @@ void InnerWidget::fill() {
Ui::AddSkip(container);
}
const auto hasCurrencyTab = !data.firstHistorySlice.list.empty();
const auto hasCreditsTab = !_state.creditsStatusSlice.list.empty()
&& _state.premiumBotId;
const auto sectionIndex = container->lifetime().make_state<int>(0);
const auto rebuildLists = [=](
const Memento::SavedState &data,
not_null<Ui::VerticalLayout*> listsContainer) {
const auto hasCurrencyTab
= !data.currencyEarn.firstHistorySlice.list.empty();
const auto hasCreditsTab = !data.creditsStatusSlice.list.empty()
&& data.premiumBotId;
const auto hasOneTab = (hasCurrencyTab || hasCreditsTab)
&& (hasCurrencyTab != hasCreditsTab);
const auto currencyTabText = tr::lng_channel_earn_currency_history(
tr::now);
const auto creditsTabText = tr::lng_channel_earn_credits_history(tr::now);
const auto creditsTabText = tr::lng_channel_earn_credits_history(
tr::now);
const auto slider = container->add(
const auto slider = listsContainer->add(
object_ptr<Ui::SlideWrap<Ui::CustomWidthSlider>>(
container,
listsContainer,
object_ptr<Ui::CustomWidthSlider>(
container,
listsContainer,
st::defaultTabsSlider)),
st::boxRowPadding);
slider->toggle(!hasOneTab, anim::type::instant);
@ -952,38 +962,43 @@ void InnerWidget::fill() {
if (hasOneTab) {
if (hasCurrencyTab) {
AddHeader(container, tr::lng_channel_earn_history_title);
AddHeader(listsContainer, tr::lng_channel_earn_history_title);
} else if (hasCreditsTab) {
AddHeader(container, tr::lng_channel_earn_credits_history);
AddHeader(
listsContainer,
tr::lng_channel_earn_credits_history);
slider->entity()->setActiveSectionFast(1);
}
} else {
slider->entity()->setActiveSectionFast(*sectionIndex);
}
const auto historyCurrencyList = container->add(
const auto tabCurrencyList = listsContainer->add(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
container,
object_ptr<Ui::VerticalLayout>(container)));
const auto historyCreditsList = container->add(
listsContainer,
object_ptr<Ui::VerticalLayout>(listsContainer)));
const auto tabCreditsList = listsContainer->add(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
container,
object_ptr<Ui::VerticalLayout>(container)));
listsContainer,
object_ptr<Ui::VerticalLayout>(listsContainer)));
rpl::single(slider->entity()->activeSection()) | rpl::then(
slider->entity()->sectionActivated()
) | rpl::start_with_next([=](int index) {
if (index == 0) {
historyCurrencyList->toggle(true, anim::type::instant);
historyCreditsList->toggle(false, anim::type::instant);
tabCurrencyList->toggle(true, anim::type::instant);
tabCreditsList->toggle(false, anim::type::instant);
} else if (index == 1) {
historyCurrencyList->toggle(false, anim::type::instant);
historyCreditsList->toggle(true, anim::type::instant);
tabCurrencyList->toggle(false, anim::type::instant);
tabCreditsList->toggle(true, anim::type::instant);
}
}, container->lifetime());
*sectionIndex = index;
}, listsContainer->lifetime());
if (hasCurrencyTab) {
Ui::AddSkip(container);
Ui::AddSkip(listsContainer);
const auto historyList = historyCurrencyList->entity();
const auto historyList = tabCurrencyList->entity();
const auto addHistoryEntry = [=](
const Data::EarnHistoryEntry &entry,
const tr::phrase<> &text) {
@ -999,7 +1014,8 @@ void InnerWidget::fill() {
text(),
st::channelEarnSemiboldLabel));
const auto isIn = entry.type == Data::EarnHistoryEntry::Type::In;
const auto isIn
= (entry.type == Data::EarnHistoryEntry::Type::In);
const auto recipient = Ui::Text::Wrapped(
{ entry.provider },
EntityType::Code);
@ -1036,7 +1052,8 @@ void InnerWidget::fill() {
dateText,
st::channelEarnHistorySubLabel)
)->setTextColorOverride(isFailed
? std::make_optional<QColor>(st::menuIconAttentionColor->c)
? std::make_optional<QColor>(
st::menuIconAttentionColor->c)
: std::nullopt);
const auto color = (isIn
@ -1045,7 +1062,11 @@ void InnerWidget::fill() {
const auto majorLabel = Ui::CreateChild<Ui::FlatLabel>(
wrap,
st::channelEarnHistoryMajorLabel);
addEmojiToMajor(majorLabel, rpl::single(entry.amount), isIn, {});
addEmojiToMajor(
majorLabel,
rpl::single(entry.amount),
isIn,
{});
majorLabel->setAttribute(Qt::WA_TransparentForMouseEvents);
majorLabel->setTextColorOverride(color);
const auto minorText = MinorPart(entry.amount);
@ -1060,7 +1081,7 @@ void InnerWidget::fill() {
rpl::single(QString()));
Ui::ToggleChildrenVisibility(wrap, true);
const auto detailsBox = [=, amount = entry.amount, peer = _peer](
const auto detailsBox = [=, peer = _peer](
not_null<Ui::GenericBox*> box) {
box->addTopButton(
st::boxTitleClose,
@ -1075,14 +1096,20 @@ void InnerWidget::fill() {
const auto majorLabel = Ui::CreateChild<Ui::FlatLabel>(
labels,
st::channelEarnOverviewMajorLabel);
addEmojiToMajor(majorLabel, rpl::single(amount), isIn, {});
majorLabel->setAttribute(Qt::WA_TransparentForMouseEvents);
addEmojiToMajor(
majorLabel,
rpl::single(entry.amount),
isIn,
{});
majorLabel->setAttribute(
Qt::WA_TransparentForMouseEvents);
majorLabel->setTextColorOverride(color);
const auto minorLabel = Ui::CreateChild<Ui::FlatLabel>(
labels,
minorText,
st::channelEarnOverviewMinorLabel);
minorLabel->setAttribute(Qt::WA_TransparentForMouseEvents);
minorLabel->setAttribute(
Qt::WA_TransparentForMouseEvents);
minorLabel->setTextColorOverride(color);
rpl::combine(
majorLabel->sizeValue(),
@ -1157,7 +1184,9 @@ void InnerWidget::fill() {
+ rect::m::sum::h(padding),
leftSize.height());
left->moveToLeft(0, 0);
right->moveToRight(padding.right(), padding.top());
right->moveToRight(
padding.right(),
padding.top());
const auto maxRightSize = box->width()
- rect::m::sum::h(st::boxRowPadding)
- rect::m::sum::h(padding)
@ -1177,11 +1206,12 @@ void InnerWidget::fill() {
p.drawRoundedRect(rect, radius, radius);
}, peerBubble->lifetime());
}
const auto closeBox = [=] { box->closeBox(); };
{
const auto &st = st::premiumPreviewDoubledLimitsBox;
box->setStyle(st);
auto button = object_ptr<Ui::RoundButton>(
container,
box,
(!entry.successLink.isEmpty())
? tr::lng_channel_earn_history_out_button()
: tr::lng_box_ok(),
@ -1191,7 +1221,8 @@ void InnerWidget::fill() {
- st.buttonPadding.left());
if (!entry.successLink.isEmpty()) {
button->setAcceptBoth();
button->addClickHandler([=](Qt::MouseButton button) {
button->addClickHandler([=](
Qt::MouseButton button) {
if (button == Qt::LeftButton) {
UrlClickHandler::Open(entry.successLink);
} else if (button == Qt::RightButton) {
@ -1199,13 +1230,13 @@ void InnerWidget::fill() {
}
});
} else {
button->setClickedCallback([=] { box->closeBox(); });
button->setClickedCallback(closeBox);
}
box->addButton(std::move(button));
}
Ui::AddSkip(box->verticalLayout());
Ui::AddSkip(box->verticalLayout());
box->addButton(tr::lng_box_ok(), [=] { box->closeBox(); });
box->addButton(tr::lng_box_ok(), closeBox);
};
button->setClickedCallback([=] {
@ -1214,7 +1245,8 @@ void InnerWidget::fill() {
wrap->geometryValue(
) | rpl::start_with_next([=](const QRect &g) {
const auto &padding = st::boxRowPadding;
const auto majorTop = (g.height() - majorLabel->height()) / 2;
const auto majorTop = (g.height() - majorLabel->height())
/ 2;
minorLabel->moveToRight(
padding.right(),
majorTop + st::channelEarnHistoryMinorLabelSkip);
@ -1224,27 +1256,28 @@ void InnerWidget::fill() {
const auto rightWrapPadding = rect::m::sum::h(padding)
+ minorLabel->width()
+ majorLabel->width();
wrap->setPadding(
st::channelEarnHistoryOuter
wrap->setPadding(st::channelEarnHistoryOuter
+ QMargins(padding.left(), 0, rightWrapPadding, 0));
button->resize(g.size());
button->lower();
}, wrap->lifetime());
};
const auto handleSlice = [=](const Data::EarnHistorySlice &slice) {
for (const auto &entry : slice.list) {
const auto handleSlice = [=](const Data::EarnHistorySlice &s) {
using Type = Data::EarnHistoryEntry::Type;
for (const auto &entry : s.list) {
addHistoryEntry(
entry,
(entry.type == Data::EarnHistoryEntry::Type::In)
(entry.type == Type::In)
? tr::lng_channel_earn_history_in
: (entry.type == Data::EarnHistoryEntry::Type::Return)
: (entry.type == Type::Return)
? tr::lng_channel_earn_history_return
: tr::lng_channel_earn_history_out);
}
historyList->resizeToWidth(container->width());
historyList->resizeToWidth(listsContainer->width());
};
handleSlice(data.firstHistorySlice);
if (!data.firstHistorySlice.allLoaded) {
const auto &firstSlice = data.currencyEarn.firstHistorySlice;
handleSlice(firstSlice);
if (!firstSlice.allLoaded) {
struct ShowMoreState final {
ShowMoreState(not_null<ChannelData*> channel)
: api(channel) {
@ -1254,15 +1287,16 @@ void InnerWidget::fill() {
Data::EarnHistorySlice::OffsetToken token;
rpl::variable<int> showed = 0;
};
const auto state = lifetime().make_state<ShowMoreState>(channel);
state->token = data.firstHistorySlice.token;
state->showed = data.firstHistorySlice.list.size();
const auto max = data.firstHistorySlice.total;
const auto wrap = container->add(
const auto state
= lifetime().make_state<ShowMoreState>(channel);
state->token = firstSlice.token;
state->showed = firstSlice.list.size();
const auto max = firstSlice.total;
const auto wrap = listsContainer->add(
object_ptr<Ui::SlideWrap<Ui::SettingsButton>>(
container,
listsContainer,
object_ptr<Ui::SettingsButton>(
container,
listsContainer,
tr::lng_channel_earn_history_show_more(
lt_count,
state->showed.value(
@ -1274,29 +1308,30 @@ void InnerWidget::fill() {
AddArrow(button);
wrap->toggle(true, anim::type::instant);
const auto handleReceived = [=](Data::EarnHistorySlice slice) {
const auto handleReceived = [=](
Data::EarnHistorySlice slice) {
state->loading = false;
handleSlice(slice);
wrap->toggle(!slice.allLoaded, anim::type::instant);
state->token = slice.token;
state->showed = state->showed.current() + slice.list.size();
state->showed = state->showed.current()
+ slice.list.size();
};
button->setClickedCallback([=] {
if (!state->loading) {
if (state->loading) {
return;
}
state->loading = true;
state->api.requestHistory(state->token, handleReceived);
}
});
}
Ui::AddSkip(container);
Ui::AddDivider(container);
Ui::AddSkip(container);
}
if (hasCreditsTab) {
const auto controller = _controller->parentController();
const auto show = controller->uiShow();
const auto premiumBot = _peer->owner().peer(_state.premiumBotId);
const auto entryClicked = [=](const Data::CreditsHistoryEntry &e) {
const auto premiumBot = _peer->owner().peer(data.premiumBotId);
const auto entryClicked = [=](
const Data::CreditsHistoryEntry &e) {
show->show(Box(
::Settings::ReceiptCreditsBox,
controller,
@ -1304,22 +1339,39 @@ void InnerWidget::fill() {
e));
};
const auto star = historyCreditsList->lifetime().make_state<QImage>(
const auto star = tabCreditsList->lifetime().make_state<QImage>(
Ui::GenerateStars(st::creditsTopupButton.height, 1));
Info::Statistics::AddCreditsHistoryList(
show,
_state.creditsStatusSlice,
historyCreditsList->entity(),
data.creditsStatusSlice,
tabCreditsList->entity(),
entryClicked,
premiumBot,
star,
true,
true);
Ui::AddSkip(container);
Ui::AddDivider(container);
Ui::AddSkip(container);
}
if (hasCurrencyTab || hasCreditsTab) {
Ui::AddSkip(listsContainer);
Ui::AddDivider(listsContainer);
Ui::AddSkip(listsContainer);
}
};
const auto historyContainer = container->add(
object_ptr<Ui::VerticalLayout>(container));
rpl::single(rpl::empty) | rpl::then(
_stateUpdated.events()
) | rpl::start_with_next([=] {
const auto listsContainer = historyContainer->add(
object_ptr<Ui::VerticalLayout>(container));
rebuildLists(_state, listsContainer);
while (historyContainer->count() > 1) {
delete historyContainer->widgetAt(0);
}
}, historyContainer->lifetime());
if (channel) {
//constexpr auto kMaxCPM = 50; // Debug.
const auto requiredLevel = Data::LevelLimits(session)