From 9509c88ef9ff458d1841c4f92a0ea81c462cca56 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 8 Aug 2022 14:32:16 +0300 Subject: [PATCH] Fix possible crash in pinned messages destruction. --- .../history/view/history_view_pinned_bar.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_bar.cpp b/Telegram/SourceFiles/history/view/history_view_pinned_bar.cpp index 7e14026d8..5634ce82c 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_bar.cpp +++ b/Telegram/SourceFiles/history/view/history_view_pinned_bar.cpp @@ -204,12 +204,20 @@ rpl::producer PinnedBarItemWithReplyMarkup( const auto messageFlag = [=](not_null item) { using Update = Data::MessageUpdate; - session->changes().messageFlagsValue( + session->changes().messageUpdates( item, - Update::Flag::ReplyMarkup + Update::Flag::ReplyMarkup | Update::Flag::Destroyed ) | rpl::start_with_next([=](const Update &update) { - pushUnique(update.item); + if (update.flags & Update::Flag::Destroyed) { + state->lifetime.destroy(); + invalidate_weak_ptrs(&state->guard); + state->hasReplyMarkup = false; + consumer.put_next(nullptr); + } else { + pushUnique(update.item); + } }, state->lifetime); + pushUnique(item); }; if (const auto item = session->data().message(fullId)) { messageFlag(item);