Fixed possible crash in loading of recent posts for statistical info.

This commit is contained in:
23rd 2023-10-11 03:58:30 +03:00 committed by John Preston
parent 736efd4692
commit aee6b6e224

View file

@ -475,11 +475,14 @@ void FillRecentPosts(
const Descriptor &descriptor, const Descriptor &descriptor,
const Data::ChannelStatistics &stats, const Data::ChannelStatistics &stats,
Fn<void(FullMsgId)> showMessageStatistic) { Fn<void(FullMsgId)> showMessageStatistic) {
if (stats.recentMessageInteractions.empty()) {
return;
}
const auto wrap = container->add( const auto wrap = container->add(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>( object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
container, container,
object_ptr<Ui::VerticalLayout>(container))); object_ptr<Ui::VerticalLayout>(container)));
wrap->toggle(false, anim::type::instant);
const auto content = wrap->entity(); const auto content = wrap->entity();
AddHeader(content, tr::lng_stats_recent_messages_title, { stats, {} }); AddHeader(content, tr::lng_stats_recent_messages_title, { stats, {} });
::Settings::AddSkip(content); ::Settings::AddSkip(content);
@ -510,12 +513,12 @@ void FillRecentPosts(
showMessageStatistic(fullId); showMessageStatistic(fullId);
}); });
::Settings::AddSkip(messageWrap); ::Settings::AddSkip(messageWrap);
content->resizeToWidth(content->width());
if (!wrap->toggled()) { if (!wrap->toggled()) {
wrap->toggle(true, anim::type::normal); wrap->toggle(true, anim::type::normal);
} }
}; };
auto foundLoaded = false;
const auto &peer = descriptor.peer; const auto &peer = descriptor.peer;
for (const auto &recent : stats.recentMessageInteractions) { for (const auto &recent : stats.recentMessageInteractions) {
const auto messageWrap = content->add( const auto messageWrap = content->add(
@ -523,15 +526,20 @@ void FillRecentPosts(
const auto msgId = recent.messageId; const auto msgId = recent.messageId;
if (const auto item = peer->owner().message(peer, msgId)) { if (const auto item = peer->owner().message(peer, msgId)) {
addMessage(messageWrap, item, recent); addMessage(messageWrap, item, recent);
foundLoaded = true;
continue; continue;
} }
const auto callback = [=] { const auto callback = crl::guard(content, [=] {
if (const auto item = peer->owner().message(peer, msgId)) { if (const auto item = peer->owner().message(peer, msgId)) {
addMessage(messageWrap, item, recent); addMessage(messageWrap, item, recent);
content->resizeToWidth(content->width());
} }
}; });
peer->session().api().requestMessageData(peer, msgId, callback); peer->session().api().requestMessageData(peer, msgId, callback);
} }
if (!foundLoaded) {
wrap->toggle(false, anim::type::instant);
}
} }
} // namespace } // namespace