diff --git a/Telegram/SourceFiles/history/view/media/history_view_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_document.cpp index f6e60f877..541e0c463 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_document.cpp @@ -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(); 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; diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp index 6176bf050..51150dace 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp @@ -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(); 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);