From 939f6095baa5c4f125a79ee1a950828253512dc2 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 1 Nov 2024 17:18:59 +0400 Subject: [PATCH] Fix possible crash in Recent Actions. --- .../admin_log/history_admin_log_inner.cpp | 19 ++++++++++++++----- .../admin_log/history_admin_log_inner.h | 8 ++++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index b67629f92..b37da32c1 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -273,13 +273,13 @@ InnerWidget::InnerWidget( _scrollDateHideTimer.setCallback([=] { scrollDateHideByTimer(); }); session().data().viewRepaintRequest( ) | rpl::start_with_next([=](auto view) { - if (view->delegate() == this) { + if (myView(view)) { repaintItem(view); } }, lifetime()); session().data().viewResizeRequest( ) | rpl::start_with_next([=](auto view) { - if (view->delegate() == this) { + if (myView(view)) { resizeItem(view); } }, lifetime()); @@ -291,7 +291,7 @@ InnerWidget::InnerWidget( }, lifetime()); session().data().viewLayoutChanged( ) | rpl::start_with_next([=](auto view) { - if (view->delegate() == this) { + if (myView(view)) { if (view->isUnderCursor()) { updateSelected(); } @@ -333,6 +333,10 @@ InnerWidget::InnerWidget( [=] { requestAdmins(); })); } +bool InnerWidget::myView(not_null view) const { + return !_items.empty() && (view->delegate().get() == this); +} + Main::Session &InnerWidget::session() const { return _controller->session(); } @@ -790,11 +794,16 @@ void InnerWidget::saveState(not_null memento) { } void InnerWidget::restoreState(not_null memento) { - _items = memento->takeItems(); - for (auto &item : _items) { + // OwnedItem::refreshView may call requestItemResize. + // So we postpone resizing until all views are created. + _items.clear(); + auto items = memento->takeItems(); + for (auto &item : items) { item.refreshView(this); _itemsByData.emplace(item->data(), item.get()); } + _items = std::move(items); + _eventIds = memento->takeEventIds(); _admins = memento->takeAdmins(); _adminsCanEdit = memento->takeAdminsCanEdit(); diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h index db52cac1c..bdf9c0491 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h @@ -229,8 +229,12 @@ private: void paintEmpty(Painter &p, not_null st); void clearAfterFilterChange(); void clearAndRequestLog(); - void addEvents(Direction direction, const QVector &events); - Element *viewForItem(const HistoryItem *item); + void addEvents( + Direction direction, + const QVector &events); + [[nodiscard]] Element *viewForItem(const HistoryItem *item); + [[nodiscard]] bool myView( + not_null view) const; void toggleScrollDateShown(); void repaintScrollDateCallback();