diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index f966a5bf8f..f010e9c600 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -2882,8 +2882,18 @@ void Session::unregisterMessageTTL( void Session::checkTTLs() { _ttlCheckTimer.cancel(); const auto now = base::unixtime::now(); - while (!_ttlMessages.empty() && _ttlMessages.begin()->first <= now) { - _ttlMessages.begin()->second.front()->destroy(); + auto expired = std::vector>(); + for (const auto &[when, items] : _ttlMessages) { + if (when > now) { + break; + } + expired.insert(expired.end(), items.begin(), items.end()); + } + if (!expired.empty()) { + notifyItemsAboutToBeDestroyed(expired); + for (const auto &item : expired) { + item->destroy(); + } } scheduleNextTTLs(); } @@ -2940,12 +2950,13 @@ void Session::processMessagesDeleted( return; } + auto toDestroy = std::vector>(); auto historiesToCheck = base::flat_set>(); for (const auto &messageId : data) { const auto i = list ? list->find(messageId.v) : Messages::iterator(); if (list && i != list->end()) { const auto history = i->second->history(); - i->second->destroy(); + toDestroy.push_back(i->second); if (!history->chatListMessageKnown()) { historiesToCheck.emplace(history); } @@ -2953,22 +2964,35 @@ void Session::processMessagesDeleted( affected->unknownMessageDeleted(messageId.v); } } + if (!toDestroy.empty()) { + notifyItemsAboutToBeDestroyed(toDestroy); + for (const auto &item : toDestroy) { + item->destroy(); + } + } for (const auto &history : historiesToCheck) { history->requestChatListMessage(); } } void Session::processNonChannelMessagesDeleted(const QVector &data) { + auto toDestroy = std::vector>(); auto historiesToCheck = base::flat_set>(); for (const auto &messageId : data) { if (const auto item = nonChannelMessage(messageId.v)) { const auto history = item->history(); - item->destroy(); + toDestroy.push_back(item); if (!history->chatListMessageKnown()) { historiesToCheck.emplace(history); } } } + if (!toDestroy.empty()) { + notifyItemsAboutToBeDestroyed(toDestroy); + for (const auto &item : toDestroy) { + item->destroy(); + } + } for (const auto &history : historiesToCheck) { history->requestChatListMessage(); } diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index af51de483a..41f2c4e1d7 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -669,6 +669,9 @@ void History::destroyMessagesByDates(TimeId minDate, TimeId maxDate) { toDestroy.push_back(message.get()); } } + if (!toDestroy.empty()) { + owner().notifyItemsAboutToBeDestroyed(toDestroy); + } for (const auto &item : toDestroy) { item->destroy(); } @@ -682,6 +685,9 @@ void History::destroyMessagesByTopic(MsgId topicRootId) { toDestroy.push_back(message.get()); } } + if (!toDestroy.empty()) { + owner().notifyItemsAboutToBeDestroyed(toDestroy); + } for (const auto &item : toDestroy) { item->destroy(); } @@ -696,6 +702,9 @@ void History::destroyMessagesBySublist(not_null sublistPeer) { toDestroy.push_back(message.get()); } } + if (!toDestroy.empty()) { + owner().notifyItemsAboutToBeDestroyed(toDestroy); + } for (const auto &item : toDestroy) { item->destroy(); } @@ -4192,12 +4201,16 @@ void History::clear(ClearType type, bool markEmpty) { _loadedAtTop = _loadedAtBottom = markEmpty; } else { // Leave the 'sending' messages in local messages. - auto local = base::flat_set>(); + auto local = std::vector>(); + local.reserve(_clientSideMessages.size()); for (const auto &item : _clientSideMessages) { if (!item->isSending()) { - local.emplace(item); + local.push_back(item); } } + if (!local.empty()) { + owner().notifyItemsAboutToBeDestroyed(local); + } for (const auto &item : local) { item->destroy(); } @@ -4256,6 +4269,9 @@ void History::clearUpTill(MsgId availableMinId) { remove.push_back(item.get()); } } + if (!remove.empty()) { + owner().notifyItemsAboutToBeDestroyed(remove); + } for (const auto &item : remove) { item->destroy(); }