From aee6b6e2244c26570866123fbd8bc5f70d0c8183 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 11 Oct 2023 03:58:30 +0300 Subject: [PATCH] Fixed possible crash in loading of recent posts for statistical info. --- .../statistics/info_statistics_inner_widget.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp b/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp index 0ab5c024c..d29ec1e21 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp +++ b/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp @@ -475,11 +475,14 @@ void FillRecentPosts( const Descriptor &descriptor, const Data::ChannelStatistics &stats, Fn showMessageStatistic) { + if (stats.recentMessageInteractions.empty()) { + return; + } + const auto wrap = container->add( object_ptr>( container, object_ptr(container))); - wrap->toggle(false, anim::type::instant); const auto content = wrap->entity(); AddHeader(content, tr::lng_stats_recent_messages_title, { stats, {} }); ::Settings::AddSkip(content); @@ -510,12 +513,12 @@ void FillRecentPosts( showMessageStatistic(fullId); }); ::Settings::AddSkip(messageWrap); - content->resizeToWidth(content->width()); if (!wrap->toggled()) { wrap->toggle(true, anim::type::normal); } }; + auto foundLoaded = false; const auto &peer = descriptor.peer; for (const auto &recent : stats.recentMessageInteractions) { const auto messageWrap = content->add( @@ -523,15 +526,20 @@ void FillRecentPosts( const auto msgId = recent.messageId; if (const auto item = peer->owner().message(peer, msgId)) { addMessage(messageWrap, item, recent); + foundLoaded = true; continue; } - const auto callback = [=] { + const auto callback = crl::guard(content, [=] { if (const auto item = peer->owner().message(peer, msgId)) { addMessage(messageWrap, item, recent); + content->resizeToWidth(content->width()); } - }; + }); peer->session().api().requestMessageData(peer, msgId, callback); } + if (!foundLoaded) { + wrap->toggle(false, anim::type::instant); + } } } // namespace