From 32d3b90cdc1dae88e2f59c8c9f47a1c230ff536a Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 29 Jan 2024 17:05:56 +0300 Subject: [PATCH] Replaced behavior of statistics info to wait all charts. --- .../info_statistics_inner_widget.cpp | 58 +++++++++++++------ .../statistics/info_statistics_inner_widget.h | 2 +- .../SourceFiles/statistics/chart_widget.cpp | 3 + 3 files changed, 43 insertions(+), 20 deletions(-) diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp b/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp index 4e50b2bf66..852f7bfdc8 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp +++ b/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp @@ -113,7 +113,8 @@ void ProcessZoom( void FillStatistic( not_null content, const Descriptor &descriptor, - Data::AnyStatistics &stats) { + Data::AnyStatistics &stats, + Fn done) { using Type = Statistic::ChartViewType; const auto &padding = st::statisticsChartEntryPadding; const auto &m = st::statisticsLayerMargins; @@ -122,6 +123,20 @@ void FillStatistic( Ui::AddDivider(c); Ui::AddSkip(c, padding.top()); }; + struct State final { + Fn done; + int pendingCount = 0; + }; + const auto state = content->lifetime().make_state( + State{ std::move(done) }); + + const auto singlePendingDone = [=] { + state->pendingCount--; + if (!state->pendingCount && state->done) { + base::take(state->done)(); + } + }; + const auto addChart = [&]( Data::StatisticalGraph &graphData, rpl::producer &&title, @@ -137,6 +152,7 @@ void FillStatistic( addSkip(content); } else if (!graphData.zoomToken.isEmpty()) { + state->pendingCount++; const auto wrap = content->add( object_ptr>( content, @@ -159,13 +175,15 @@ void FillStatistic( if (graph.chart) { widget->setChartData(graph.chart, type); - wrap->toggle(true, anim::type::normal); + wrap->toggle(true, anim::type::instant); ProcessZoom(descriptor, widget, graph.zoomToken, type); widget->setTitle(rpl::duplicate(title)); } else if (!graph.error.isEmpty()) { } - }, [](const QString &error) { - }, [] { + }, [=](const QString &error) { + singlePendingDone(); + }, [=] { + singlePendingDone(); }, content->lifetime()); addSkip(wrap->entity()); @@ -605,12 +623,6 @@ void InnerWidget::load() { _loaded.events_starting_with(false) | rpl::map(!rpl::mappers::_1), _showFinished.events()); - const auto finishLoading = [=] { - _loaded.fire(true); - inner->resizeToWidth(width()); - inner->showChildren(); - }; - _showFinished.events( ) | rpl::take(1) | rpl::start_with_next([=] { if (!_contextId && !_storyId) { @@ -622,7 +634,6 @@ void InnerWidget::load() { }; fill(); - finishLoading(); }, lifetime()); } else { const auto lifetimeApi = lifetime().make_state(); @@ -644,7 +655,6 @@ void InnerWidget::load() { } fill(); - finishLoading(); lifetimeApi->destroy(); }); } @@ -652,17 +662,28 @@ void InnerWidget::load() { } void InnerWidget::fill() { - const auto inner = this; + const auto wrap = this->add( + object_ptr>( + this, + object_ptr(this))); + wrap->toggle(false, anim::type::instant); + const auto inner = wrap->entity(); const auto descriptor = Descriptor{ _peer, lifetime().make_state(_peer->asChannel()), _controller->uiShow()->toastParent(), }; + const auto finishLoading = [=] { + _loaded.fire(true); + wrap->toggle(true, anim::type::instant); + this->resizeToWidth(width()); + this->showChildren(); + }; if (_state.stats.message) { if (const auto i = _peer->owner().message(_contextId)) { Ui::AddSkip(inner); const auto preview = inner->add( - object_ptr(this, i, QImage())); + object_ptr(inner, i, QImage())); AddContextMenu(preview, _controller, i); Ui::AddSkip(inner); Ui::AddDivider(inner); @@ -671,7 +692,7 @@ void InnerWidget::fill() { if (const auto story = _peer->owner().stories().lookup(_storyId)) { Ui::AddSkip(inner); const auto preview = inner->add( - object_ptr(this, *story, QImage())); + object_ptr(inner, *story, QImage())); preview->setAttribute(Qt::WA_TransparentForMouseEvents); Ui::AddSkip(inner); Ui::AddDivider(inner); @@ -681,11 +702,11 @@ void InnerWidget::fill() { if (_state.stats.channel) { FillOverview(inner, _state.stats, true); } - FillStatistic(inner, descriptor, _state.stats); + FillStatistic(inner, descriptor, _state.stats, finishLoading); const auto &channel = _state.stats.channel; const auto &supergroup = _state.stats.supergroup; if (channel) { - fillRecentPosts(); + fillRecentPosts(inner); } else if (supergroup) { const auto showPeerInfo = [=](not_null peer) { _showRequests.fire({ .info = peer->id }); @@ -742,13 +763,12 @@ void InnerWidget::fill() { } } -void InnerWidget::fillRecentPosts() { +void InnerWidget::fillRecentPosts(not_null container) { const auto &stats = _state.stats.channel; if (!stats || stats.recentMessageInteractions.empty()) { return; } _messagePreviews.reserve(stats.recentMessageInteractions.size()); - const auto container = this; const auto wrap = container->add( object_ptr>( diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.h b/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.h index ada52f65c9..c0a31231e7 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.h +++ b/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.h @@ -54,7 +54,7 @@ public: private: void load(); void fill(); - void fillRecentPosts(); + void fillRecentPosts(not_null container); not_null _controller; not_null _peer; diff --git a/Telegram/SourceFiles/statistics/chart_widget.cpp b/Telegram/SourceFiles/statistics/chart_widget.cpp index ef7319581f..93d225c705 100644 --- a/Telegram/SourceFiles/statistics/chart_widget.cpp +++ b/Telegram/SourceFiles/statistics/chart_widget.cpp @@ -851,6 +851,9 @@ ChartWidget::ChartWidget(not_null parent) } int ChartWidget::resizeGetHeight(int newWidth) { + if (newWidth <= 0) { + return 0; + } if (_filterButtons) { _filterButtons->resizeToWidth(newWidth); }