diff --git a/Telegram/SourceFiles/boxes/moderate_messages_box.cpp b/Telegram/SourceFiles/boxes/moderate_messages_box.cpp index 1b493eca61..e9e5369f0a 100644 --- a/Telegram/SourceFiles/boxes/moderate_messages_box.cpp +++ b/Telegram/SourceFiles/boxes/moderate_messages_box.cpp @@ -138,6 +138,8 @@ void CreateModerateMessagesBox( not_null box, const HistoryItemsList &items, Fn confirmed) { + Expects(!items.empty()); + using Controller = Ui::ExpandablePeerListController; const auto [allCanBan, allCanDelete, participants] @@ -158,8 +160,12 @@ void CreateModerateMessagesBox( participants.size()).width(), 0); - const auto session = &items.front()->history()->session(); - const auto historyPeerId = items.front()->history()->peer->id; + const auto itemsCount = int(items.size()); + const auto firstItem = items.front(); + const auto history = firstItem->history(); + const auto session = &history->session(); + const auto historyPeerId = history->peer->id; + const auto ids = session->data().itemsToIds(items); using Request = Fn, not_null)>; const auto sequentiallyRequest = [=]( @@ -242,11 +248,11 @@ void CreateModerateMessagesBox( const auto title = box->addRow( object_ptr( box, - (items.size() == 1) + (itemsCount == 1) ? tr::lng_selected_delete_sure_this() : tr::lng_selected_delete_sure( lt_count, - rpl::single(items.size()) | tr::to_count()), + rpl::single(itemsCount) | tr::to_count()), st::boxLabel)); Ui::AddSkip(inner); Ui::AddSkip(inner); @@ -264,7 +270,6 @@ void CreateModerateMessagesBox( Ui::AddExpandablePeerList(report, controller, inner); handleSubmition(report); - const auto ids = items.front()->from()->owner().itemsToIds(items); handleConfirmation(report, controller, [=]( not_null p, not_null c) { @@ -296,12 +301,11 @@ void CreateModerateMessagesBox( : tr::lng_delete_all_from_user( tr::now, lt_user, - Ui::Text::Bold(items.front()->from()->name()), + Ui::Text::Bold(firstItem->from()->name()), Ui::Text::WithEntities), false, st::defaultBoxCheckbox), st::boxRowPadding + buttonPadding); - const auto history = items.front()->history(); auto messagesCounts = MessagesCountValue(history, participants); const auto controller = box->lifetime().make_state( @@ -311,6 +315,10 @@ void CreateModerateMessagesBox( }); Ui::AddExpandablePeerList(deleteAll, controller, inner); { + auto itemFromIds = items | ranges::views::transform([]( + const auto &item) { + return item->from()->id; + }) | ranges::to_vector; tr::lng_selected_delete_sure( lt_count, rpl::combine( @@ -320,7 +328,7 @@ void CreateModerateMessagesBox( : rpl::merge( controller->toggleRequestsFromInner.events(), controller->checkAllRequests.events()) - ) | rpl::map([=, s = items.size()](const auto &map, bool c) { + ) | rpl::map([=, s = itemsCount](const auto &map, bool c) { const auto checked = (isSingle && !c) ? Participants() : controller->collectRequests @@ -335,9 +343,9 @@ void CreateModerateMessagesBox( } } } - for (const auto &item : items) { + for (const auto &fromId : itemFromIds) { for (const auto &peer : checked) { - if (peer->id == item->from()->id) { + if (peer->id == fromId) { result--; break; }