Fix possible crash with invalidated views.

This commit is contained in:
John Preston 2018-03-08 13:47:31 +03:00
parent 321f5d879d
commit 61700577d0
3 changed files with 25 additions and 4 deletions

View file

@ -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<const HistoryItem*> item) {
_dragSelTo = nullptr;
update();
}
if (_scrollDateLastItem && _scrollDateLastItem->data() == item) {
_scrollDateLastItem = nullptr;
}
mouseActionUpdate();
}
void HistoryInner::refreshView(not_null<HistoryItem*> 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) {

View file

@ -213,6 +213,7 @@ private:
void toggleFavedSticker(not_null<DocumentData*> document);
void itemRemoved(not_null<const HistoryItem*> item);
void refreshView(not_null<HistoryItem*> item);
void touchResetSpeed();
void touchUpdateSpeed();

View file

@ -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()) {