diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index c8b6efcd25..70cc1f954f 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -785,6 +785,8 @@ void DeleteMessagesBox::deleteAndClear() { _deleteConfirmedCallback(); } + auto remove = std::vector>(); + remove.reserve(_ids.size()); base::flat_map, QVector> idsByPeer; base::flat_map, QVector> scheduledIdsByPeer; for (const auto itemId : _ids) { @@ -801,15 +803,9 @@ void DeleteMessagesBox::deleteAndClear() { } continue; } - const auto wasOnServer = IsServerMsgId(item->id); - const auto wasLast = (history->lastMessage() == item); - const auto wasInChats = (history->chatListMessage() == item); - item->destroy(); - - if (wasOnServer) { + remove.push_back(item); + if (IsServerMsgId(item->id)) { idsByPeer[history->peer].push_back(MTP_int(itemId.msg)); - } else if (wasLast || wasInChats) { - history->requestChatListMessage(); } } } @@ -826,6 +822,17 @@ void DeleteMessagesBox::deleteAndClear() { }).send(); } + for (const auto item : remove) { + const auto history = item->history(); + const auto wasLast = (history->lastMessage() == item); + const auto wasInChats = (history->chatListMessage() == item); + item->destroy(); + + if (wasLast || wasInChats) { + history->requestChatListMessage(); + } + } + const auto session = _session; Ui::hideLayer(); session->data().sendHistoryChangeNotifications();