diff --git a/Telegram/SourceFiles/history/view/history_view_sublist_section.cpp b/Telegram/SourceFiles/history/view/history_view_sublist_section.cpp index 7481b5eb5..a1c9578f8 100644 --- a/Telegram/SourceFiles/history/view/history_view_sublist_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_sublist_section.cpp @@ -293,6 +293,10 @@ bool SublistWidget::showInternal( return false; } +bool SublistWidget::sameTypeAs(not_null memento) { + return dynamic_cast(memento.get()) != nullptr; +} + void SublistWidget::setInternalState( const QRect &geometry, not_null memento) { diff --git a/Telegram/SourceFiles/history/view/history_view_sublist_section.h b/Telegram/SourceFiles/history/view/history_view_sublist_section.h index 008f521c5..819ce363c 100644 --- a/Telegram/SourceFiles/history/view/history_view_sublist_section.h +++ b/Telegram/SourceFiles/history/view/history_view_sublist_section.h @@ -58,6 +58,8 @@ public: bool showInternal( not_null memento, const Window::SectionShow ¶ms) override; + bool sameTypeAs(not_null memento) override; + std::shared_ptr createMemento() override; bool showMessage( PeerId peerId, diff --git a/Telegram/SourceFiles/info/saved/info_saved_sublists_widget.cpp b/Telegram/SourceFiles/info/saved/info_saved_sublists_widget.cpp index db3990963..41c9eafa6 100644 --- a/Telegram/SourceFiles/info/saved/info_saved_sublists_widget.cpp +++ b/Telegram/SourceFiles/info/saved/info_saved_sublists_widget.cpp @@ -60,9 +60,12 @@ SublistsWidget::SublistsWidget( _list->chosenRow() | rpl::start_with_next([=](Dialogs::ChosenRow row) { if (const auto sublist = row.key.sublist()) { + using namespace Window; + auto params = SectionShow(SectionShow::Way::Forward); + params.dropSameFromStack = true; controller->showSection( std::make_shared(sublist), - Window::SectionShow::Way::Forward); + params); } }, _list->lifetime()); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 511954377..a62d53826 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1379,7 +1379,7 @@ void MainWidget::showHistory( if (!back && (way != Way::ClearStack)) { // This may modify the current section, for example remove its contents. - saveSectionInStack(); + saveSectionInStack(params); } if (_history->peer() @@ -1501,13 +1501,23 @@ Ui::ChatTheme *MainWidget::customChatTheme() const { return _history->customChatTheme(); } -void MainWidget::saveSectionInStack() { +bool MainWidget::saveSectionInStack( + const SectionShow ¶ms, + Window::SectionWidget *newMainSection) { if (_mainSection) { if (auto memento = _mainSection->createMemento()) { + if (params.dropSameFromStack + && newMainSection + && newMainSection->sameTypeAs(memento.get())) { + // When choosing saved sublist we want to save the original + // "Saved Messages" in the stack, but don't save every + // sublist in a new stack entry when clicking them through. + return false; + } _stack.push_back(std::make_unique( std::move(memento))); } else { - return; + return false; } } else if (const auto history = _history->history()) { _stack.push_back(std::make_unique( @@ -1515,7 +1525,7 @@ void MainWidget::saveSectionInStack() { _history->msgId(), _history->replyReturns())); } else { - return; + return false; } const auto raw = _stack.back().get(); raw->setThirdSectionWeak(_thirdSection.data()); @@ -1528,6 +1538,7 @@ void MainWidget::saveSectionInStack() { } } }, raw->lifetime()); + return true; } void MainWidget::showSection( @@ -1730,7 +1741,11 @@ void MainWidget::showNewSection( if (saveInStack) { // This may modify the current section, for example remove its contents. - saveSectionInStack(); + if (!saveSectionInStack(params, newMainSection)) { + saveInStack = false; + animatedShow = false; + animationParams = Window::SectionSlideParams(); + } } auto &settingSection = newThirdSection ? _thirdSection diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index de94e66da..d407f8496 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -286,7 +286,9 @@ private: Window::SectionSlideParams prepareHistoryAnimation(PeerId historyPeerId); Window::SectionSlideParams prepareDialogsAnimation(); - void saveSectionInStack(); + bool saveSectionInStack( + const SectionShow ¶ms, + Window::SectionWidget *newMainSection = nullptr); int getMainSectionTop() const; int getThirdSectionTop() const; diff --git a/Telegram/SourceFiles/window/section_widget.h b/Telegram/SourceFiles/window/section_widget.h index 52b94f702..10cf3f1e9 100644 --- a/Telegram/SourceFiles/window/section_widget.h +++ b/Telegram/SourceFiles/window/section_widget.h @@ -138,6 +138,9 @@ public: virtual bool showInternal( not_null memento, const SectionShow ¶ms) = 0; + virtual bool sameTypeAs(not_null memento) { + return false; + } virtual bool showMessage( PeerId peerId, diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index ac23dfae4..03a60fcac 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -162,6 +162,7 @@ struct SectionShow { bool childColumn = false; bool forbidLayer = false; bool reapplyLocalDraft = false; + bool dropSameFromStack = false; Origin origin; };