From 61700577d0f857148f372aba12f0005f29f86c49 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 8 Mar 2018 13:47:31 +0300 Subject: [PATCH] Fix possible crash with invalidated views. --- .../history/history_inner_widget.cpp | 24 +++++++++++++++++++ .../history/history_inner_widget.h | 1 + .../SourceFiles/history/history_widget.cpp | 4 ---- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index b7e25c257..e4e914333 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -139,6 +139,10 @@ HistoryInner::HistoryInner( ) | rpl::start_with_next( [this](auto item) { itemRemoved(item); }, lifetime()); + Auth().data().itemViewRefreshRequest( + ) | rpl::start_with_next([this](auto item) { + refreshView(item); + }, lifetime()); rpl::merge( Auth().data().historyUnloaded(), Auth().data().historyCleared() @@ -1212,9 +1216,29 @@ void HistoryInner::itemRemoved(not_null item) { _dragSelTo = nullptr; update(); } + if (_scrollDateLastItem && _scrollDateLastItem->data() == item) { + _scrollDateLastItem = nullptr; + } mouseActionUpdate(); } +void HistoryInner::refreshView(not_null item) { + const auto dragSelFrom = (_dragSelFrom && _dragSelFrom->data() == item); + const auto dragSelTo = (_dragSelTo && _dragSelTo->data() == item); + const auto scrollDateLastItem = (_scrollDateLastItem + && _scrollDateLastItem->data() == item); + item->refreshMainView(); + if (dragSelFrom) { + _dragSelFrom = item->mainView(); + } + if (dragSelTo) { + _dragSelTo = item->mainView(); + } + if (scrollDateLastItem) { + _scrollDateLastItem = item->mainView(); + } +} + void HistoryInner::mouseActionFinish( const QPoint &screenPos, Qt::MouseButton button) { diff --git a/Telegram/SourceFiles/history/history_inner_widget.h b/Telegram/SourceFiles/history/history_inner_widget.h index 4134a5ecc..9f8487298 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -213,6 +213,7 @@ private: void toggleFavedSticker(not_null document); void itemRemoved(not_null item); + void refreshView(not_null item); void touchResetSpeed(); void touchUpdateSpeed(); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index e80a1cb0b..180631c95 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -573,10 +573,6 @@ HistoryWidget::HistoryWidget( updateHistoryGeometry(); } }, lifetime()); - Auth().data().itemViewRefreshRequest( - ) | rpl::start_with_next([this](auto item) { - item->refreshMainView(); - }, lifetime()); Auth().data().animationPlayInlineRequest( ) | rpl::start_with_next([this](auto item) { if (const auto view = item->mainView()) {