[thanos] Broadcast item-about-to-destroy on TTL and clear paths too.

This commit is contained in:
23rd
2026-05-22 13:20:33 +03:00
parent f037e75ba0
commit 6c88a90d28
2 changed files with 46 additions and 6 deletions
+28 -4
View File
@@ -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<not_null<HistoryItem*>>();
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<not_null<HistoryItem*>>();
auto historiesToCheck = base::flat_set<not_null<History*>>();
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<MTPint> &data) {
auto toDestroy = std::vector<not_null<HistoryItem*>>();
auto historiesToCheck = base::flat_set<not_null<History*>>();
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();
}
+18 -2
View File
@@ -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<PeerData*> 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<not_null<HistoryItem*>>();
auto local = std::vector<not_null<HistoryItem*>>();
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();
}