Fixed possible crash on deleting of media message with ttl.

This commit is contained in:
23rd 2024-01-14 12:43:32 +03:00 committed by John Preston
parent a2c0491ae0
commit 46ddc7364c
2 changed files with 12 additions and 7 deletions

View file

@ -309,18 +309,20 @@ Document::Document(
}, *lifetime);
_drawTtl = CreateTtlPaintCallback(lifetime, [=] { repaint(); });
} else if (!_parent->data()->out()) {
const auto &data = &_parent->data()->history()->owner();
_parent->data()->removeFromSharedMediaIndex();
setDocumentLinks(_data, realParent, [=] {
_openl = nullptr;
auto lifetime = std::make_shared<rpl::lifetime>();
TTLVoiceStops(fullId) | rpl::start_with_next([=]() mutable {
const auto item = _parent->data();
if (lifetime) {
base::take(lifetime)->destroy();
}
// Destroys this.
ClearMediaAsExpired(item);
if (const auto item = data->message(fullId)) {
// Destroys this.
ClearMediaAsExpired(item);
}
}, *lifetime);
return false;

View file

@ -150,17 +150,20 @@ Gif::Gif(
_drawTtl = CreateTtlPaintCallback([=] { repaint(); });
}
const auto fullId = _realParent->fullId();
const auto &data = &_parent->data()->history()->owner();
const auto isOut = _parent->data()->out();
_parent->data()->removeFromSharedMediaIndex();
setDocumentLinks(_data, realParent, [=] {
auto lifetime = std::make_shared<rpl::lifetime>();
TTLVoiceStops(fullId) | rpl::start_with_next([=]() mutable {
const auto item = _parent->data();
if (lifetime) {
base::take(lifetime)->destroy();
}
if (!item->out()) {
// Destroys this.
ClearMediaAsExpired(item);
if (!isOut) {
if (const auto item = data->message(fullId)) {
// Destroys this.
ClearMediaAsExpired(item);
}
}
}, *lifetime);