Added support of MTP updates to lists of credits history entries.

This commit is contained in:
23rd 2024-06-21 15:17:55 +03:00 committed by John Preston
parent 0dc92762bc
commit 101dbdf243

View file

@ -555,23 +555,22 @@ void InnerWidget::fill() {
void InnerWidget::fillHistory() { void InnerWidget::fillHistory() {
const auto container = this; const auto container = this;
Ui::AddSkip(container, st::settingsPremiumOptionsPadding.top());
const auto history = container->add( const auto history = container->add(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>( object_ptr<Ui::VerticalLayout>(container));
container,
object_ptr<Ui::VerticalLayout>(container)));
const auto content = history->entity();
Ui::AddSkip(content, st::settingsPremiumOptionsPadding.top()); const auto sectionIndex = history->lifetime().make_state<int>(0);
const auto fill = [=]( const auto fill = [=](
not_null<PeerData*> premiumBot, not_null<PeerData*> premiumBot,
const Data::CreditsStatusSlice &fullSlice, const Data::CreditsStatusSlice &fullSlice,
const Data::CreditsStatusSlice &inSlice, const Data::CreditsStatusSlice &inSlice,
const Data::CreditsStatusSlice &outSlice) { const Data::CreditsStatusSlice &outSlice) {
const auto inner = content;
if (fullSlice.list.empty()) { if (fullSlice.list.empty()) {
return; return;
} }
const auto inner = history->add(
object_ptr<Ui::VerticalLayout>(history));
const auto hasOneTab = inSlice.list.empty() && outSlice.list.empty(); const auto hasOneTab = inSlice.list.empty() && outSlice.list.empty();
const auto hasIn = !inSlice.list.empty(); const auto hasIn = !inSlice.list.empty();
const auto hasOut = !outSlice.list.empty(); const auto hasOut = !outSlice.list.empty();
@ -622,6 +621,8 @@ void InnerWidget::fillHistory() {
slider->entity()->addSection(outTabText); slider->entity()->addSection(outTabText);
} }
slider->entity()->setActiveSectionFast(*sectionIndex);
{ {
const auto &st = st::defaultTabsSlider; const auto &st = st::defaultTabsSlider;
slider->entity()->setNaturalWidth(0 slider->entity()->setNaturalWidth(0
@ -644,7 +645,7 @@ void InnerWidget::fillHistory() {
inner, inner,
object_ptr<Ui::VerticalLayout>(inner))); object_ptr<Ui::VerticalLayout>(inner)));
rpl::single(0) | rpl::then( rpl::single(slider->entity()->activeSection()) | rpl::then(
slider->entity()->sectionActivated() slider->entity()->sectionActivated()
) | rpl::start_with_next([=](int index) { ) | rpl::start_with_next([=](int index) {
if (index == 0) { if (index == 0) {
@ -660,6 +661,7 @@ void InnerWidget::fillHistory() {
fullWrap->toggle(false, anim::type::instant); fullWrap->toggle(false, anim::type::instant);
inWrap->toggle(false, anim::type::instant); inWrap->toggle(false, anim::type::instant);
} }
*sectionIndex = index;
}, inner->lifetime()); }, inner->lifetime());
const auto controller = _controller->parentController(); const auto controller = _controller->parentController();
@ -704,12 +706,12 @@ void InnerWidget::fillHistory() {
Ui::AddSkip(inner); Ui::AddSkip(inner);
Ui::AddSkip(inner); Ui::AddSkip(inner);
inner->resizeToWidth(container->width());
}; };
const auto apiLifetime = content->lifetime().make_state<rpl::lifetime>(); const auto apiLifetime = history->lifetime().make_state<rpl::lifetime>();
{ rpl::single(rpl::empty) | rpl::then(
_stateUpdated.events()
) | rpl::start_with_next([=] {
using Api = Api::CreditsHistory; using Api = Api::CreditsHistory;
const auto apiFull = apiLifetime->make_state<Api>(_peer, true, true); const auto apiFull = apiLifetime->make_state<Api>(_peer, true, true);
const auto apiIn = apiLifetime->make_state<Api>(_peer, true, false); const auto apiIn = apiLifetime->make_state<Api>(_peer, true, false);
@ -721,12 +723,16 @@ void InnerWidget::fillHistory() {
&_controller->session() &_controller->session()
) | rpl::start_with_next([=](not_null<PeerData*> bot) { ) | rpl::start_with_next([=](not_null<PeerData*> bot) {
fill(bot, fullSlice, inSlice, outSlice); fill(bot, fullSlice, inSlice, outSlice);
container->resizeToWidth(container->width());
while (history->count() > 1) {
delete history->widgetAt(0);
}
apiLifetime->destroy(); apiLifetime->destroy();
}, *apiLifetime); }, *apiLifetime);
}); });
}); });
}); });
} }, history->lifetime());
} }
void InnerWidget::saveState(not_null<Memento*> memento) { void InnerWidget::saveState(not_null<Memento*> memento) {