Re-index a sent message only when its thread moves

Task: 2026/08/18/repair-shared-media-index-and-count-bookkeeping
This commit is contained in:
John Preston
2026-08-19 03:36:32 +04:00
committed by 23rd
parent a3296c6cef
commit c5e7edef8b

View File

@@ -2656,9 +2656,9 @@ void HistoryItem::applySentMessage(const MTPDmessage &data) {
_flags &= ~MessageFlag::InvertMedia;
}
if (!isLocalUpdateMedia()) {
removeFromSharedMediaIndex();
}
const auto wasTypes = sharedMediaTypes();
const auto wasTopicRootId = topicRootId();
const auto wasSublistPeerId = sublistPeerId();
updateSentContent(data);
updateReplyMarkup(HistoryMessageMarkupData(data.vreply_markup()));
updateForwardedInfo(data.vfwd_from());
@@ -2690,6 +2690,19 @@ void HistoryItem::applySentMessage(const MTPDmessage &data) {
}
setPostAuthor(data.vpost_author().value_or_empty());
contributeToSlowmode(data.vdate().v);
if (isRegular()
&& !isLocalUpdateMedia()
&& (topicRootId() != wasTopicRootId
|| sublistPeerId() != wasSublistPeerId)) {
if (wasTypes) {
_history->session().storage().remove(Storage::SharedMediaRemoveOne(
_history->peer->id,
wasTopicRootId,
wasSublistPeerId,
wasTypes,
id));
}
}
addToSharedMediaIndex();
setIsPinned(data.is_pinned());
addToMessagesIndex();