diff --git a/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.cpp b/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.cpp index 74f4cf99c..26b12a690 100644 --- a/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.cpp +++ b/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_statistics.h" #include "boxes/peers/edit_peer_invite_link.h" +#include "info/boosts/info_boosts_widget.h" #include "info/info_controller.h" #include "info/statistics/info_statistics_list_controllers.h" #include "lang/lang_keys.h" @@ -182,87 +183,108 @@ InnerWidget::InnerWidget( , _controller(controller) , _peer(peer) , _show(controller->uiShow()) { - const auto api = lifetime().make_state(peer); +} - const auto fakeShowed = lifetime().make_state>(); +void InnerWidget::load() { + const auto api = lifetime().make_state(_peer); _showFinished.events( ) | rpl::take(1) | rpl::start_with_next([=] { api->request( ) | rpl::start_with_error_done([](const QString &error) { }, [=] { - const auto status = api->boostStatus(); - const auto inner = this; - - { - auto dividerContent = object_ptr(inner); - Ui::FillBoostLimit( - fakeShowed->events(), - rpl::single(status.overview.isBoosted), - dividerContent.data(), - Ui::BoostBoxData{ - .boost = Ui::BoostCounters{ - .level = status.overview.level, - .boosts = status.overview.boostCount, - .thisLevelBoosts - = status.overview.currentLevelBoostCount, - .nextLevelBoosts - = status.overview.nextLevelBoostCount, - .mine = status.overview.isBoosted, - } - }, - st::statisticsLimitsLinePadding); - inner->add(object_ptr( - inner, - std::move(dividerContent), - st::statisticsLimitsDividerPadding)); - } - - FillOverview(inner, status); - - ::Settings::AddSkip(inner); - ::Settings::AddDivider(inner); - ::Settings::AddSkip(inner); - - if (status.firstSlice.total > 0) { - ::Settings::AddSkip(inner); - using PeerPtr = not_null; - const auto header = inner->add( - object_ptr(inner), - st::statisticsLayerMargins - + st::boostsChartHeaderPadding); - header->resizeToWidth(header->width()); - header->setTitle(tr::lng_boosts_list_title( - tr::now, - lt_count, - status.firstSlice.total)); - header->setSubTitle({}); - Statistics::AddBoostsList( - status.firstSlice, - inner, - [=](PeerPtr p) { controller->showPeerInfo(p); }, - peer, - tr::lng_boosts_title()); - ::Settings::AddSkip(inner); - ::Settings::AddDividerText( - inner, - tr::lng_boosts_list_subtext()); - ::Settings::AddSkip(inner); - } - - ::Settings::AddSkip(inner); - AddHeader(inner, tr::lng_boosts_link_title); - ::Settings::AddSkip(inner, st::boostsLinkSkip); - FillShareLink(inner, _show, status.link, peer); - ::Settings::AddSkip(inner); - ::Settings::AddDividerText(inner, tr::lng_boosts_link_subtext()); - - resizeToWidth(width()); - crl::on_main([=]{ fakeShowed->fire({}); }); + _state = api->boostStatus(); + fill(); }, lifetime()); }, lifetime()); } +void InnerWidget::fill() { + const auto fakeShowed = lifetime().make_state>(); + const auto &status = _state; + const auto inner = this; + + { + auto dividerContent = object_ptr(inner); + Ui::FillBoostLimit( + fakeShowed->events(), + rpl::single(status.overview.isBoosted), + dividerContent.data(), + Ui::BoostBoxData{ + .boost = Ui::BoostCounters{ + .level = status.overview.level, + .boosts = status.overview.boostCount, + .thisLevelBoosts + = status.overview.currentLevelBoostCount, + .nextLevelBoosts + = status.overview.nextLevelBoostCount, + .mine = status.overview.isBoosted, + } + }, + st::statisticsLimitsLinePadding); + inner->add(object_ptr( + inner, + std::move(dividerContent), + st::statisticsLimitsDividerPadding)); + } + + FillOverview(inner, status); + + ::Settings::AddSkip(inner); + ::Settings::AddDivider(inner); + ::Settings::AddSkip(inner); + + if (status.firstSlice.total > 0) { + ::Settings::AddSkip(inner); + using PeerPtr = not_null; + const auto header = inner->add( + object_ptr(inner), + st::statisticsLayerMargins + + st::boostsChartHeaderPadding); + header->resizeToWidth(header->width()); + header->setTitle(tr::lng_boosts_list_title( + tr::now, + lt_count, + status.firstSlice.total)); + header->setSubTitle({}); + Statistics::AddBoostsList( + status.firstSlice, + inner, + [=](PeerPtr p) { _controller->showPeerInfo(p); }, + _peer, + tr::lng_boosts_title()); + ::Settings::AddSkip(inner); + ::Settings::AddDividerText( + inner, + tr::lng_boosts_list_subtext()); + ::Settings::AddSkip(inner); + } + + ::Settings::AddSkip(inner); + AddHeader(inner, tr::lng_boosts_link_title); + ::Settings::AddSkip(inner, st::boostsLinkSkip); + FillShareLink(inner, _show, status.link, _peer); + ::Settings::AddSkip(inner); + ::Settings::AddDividerText(inner, tr::lng_boosts_link_subtext()); + + resizeToWidth(width()); + crl::on_main([=]{ fakeShowed->fire({}); }); +} + +void InnerWidget::saveState(not_null memento) { + memento->setState(base::take(_state)); +} + +void InnerWidget::restoreState(not_null memento) { + _state = memento->state(); + if (!_state.link.isEmpty()) { + fill(); + } else { + load(); + } + Ui::RpWidget::resizeToWidth(width()); +} + rpl::producer InnerWidget::scrollToRequests() const { return _scrollToRequests.events(); } diff --git a/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.h b/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.h index 8dad4c73a..3161f81c0 100644 --- a/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.h +++ b/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.h @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "data/data_boosts.h" #include "ui/widgets/scroll_area.h" #include "ui/wrap/vertical_layout.h" @@ -39,11 +40,19 @@ public: void showFinished(); + void saveState(not_null memento); + void restoreState(not_null memento); + private: + void load(); + void fill(); + not_null _controller; not_null _peer; std::shared_ptr _show; + Data::BoostStatus _state; + rpl::event_stream _scrollToRequests; rpl::event_stream _showRequests; rpl::event_stream<> _showFinished; diff --git a/Telegram/SourceFiles/info/boosts/info_boosts_widget.cpp b/Telegram/SourceFiles/info/boosts/info_boosts_widget.cpp index c5b651304..2679f67a0 100644 --- a/Telegram/SourceFiles/info/boosts/info_boosts_widget.cpp +++ b/Telegram/SourceFiles/info/boosts/info_boosts_widget.cpp @@ -31,6 +31,14 @@ Section Memento::section() const { return Section(Section::Type::Boosts); } +void Memento::setState(SavedState state) { + _state = std::move(state); +} + +Memento::SavedState Memento::state() { + return base::take(_state); +} + object_ptr Memento::createWidget( QWidget *parent, not_null controller, @@ -75,7 +83,7 @@ void Widget::setInternalState( not_null memento) { setGeometry(geometry); Ui::SendPendingMoveResizeEvents(this); - // restoreState(memento); + restoreState(memento); } rpl::producer Widget::desiredShadowVisibility() const { @@ -88,10 +96,20 @@ void Widget::showFinished() { std::shared_ptr Widget::doCreateMemento() { auto result = std::make_shared(controller()); - // saveState(result.get()); + saveState(result.get()); return result; } +void Widget::saveState(not_null memento) { + memento->setScrollTop(scrollTopSave()); + _inner->saveState(memento); +} + +void Widget::restoreState(not_null memento) { + _inner->restoreState(memento); + scrollTopRestore(memento->scrollTop()); +} + std::shared_ptr Make(not_null peer) { return std::make_shared( std::vector>( diff --git a/Telegram/SourceFiles/info/boosts/info_boosts_widget.h b/Telegram/SourceFiles/info/boosts/info_boosts_widget.h index a53dd07df..d67648267 100644 --- a/Telegram/SourceFiles/info/boosts/info_boosts_widget.h +++ b/Telegram/SourceFiles/info/boosts/info_boosts_widget.h @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "data/data_boosts.h" #include "info/info_content_widget.h" namespace Info::Boosts { @@ -26,6 +27,14 @@ public: Section section() const override; + using SavedState = Data::BoostStatus; + + void setState(SavedState states); + [[nodiscard]] SavedState state(); + +private: + SavedState _state; + }; class Widget final : public ContentWidget {