Don't push sublists to stack endlessly.

This commit is contained in:
John Preston 2024-01-02 14:48:51 +04:00
parent bdf67645bb
commit 382dab4ecb
7 changed files with 37 additions and 7 deletions

View file

@ -293,6 +293,10 @@ bool SublistWidget::showInternal(
return false; return false;
} }
bool SublistWidget::sameTypeAs(not_null<Window::SectionMemento*> memento) {
return dynamic_cast<SublistMemento*>(memento.get()) != nullptr;
}
void SublistWidget::setInternalState( void SublistWidget::setInternalState(
const QRect &geometry, const QRect &geometry,
not_null<SublistMemento*> memento) { not_null<SublistMemento*> memento) {

View file

@ -58,6 +58,8 @@ public:
bool showInternal( bool showInternal(
not_null<Window::SectionMemento*> memento, not_null<Window::SectionMemento*> memento,
const Window::SectionShow &params) override; const Window::SectionShow &params) override;
bool sameTypeAs(not_null<Window::SectionMemento*> memento) override;
std::shared_ptr<Window::SectionMemento> createMemento() override; std::shared_ptr<Window::SectionMemento> createMemento() override;
bool showMessage( bool showMessage(
PeerId peerId, PeerId peerId,

View file

@ -60,9 +60,12 @@ SublistsWidget::SublistsWidget(
_list->chosenRow() | rpl::start_with_next([=](Dialogs::ChosenRow row) { _list->chosenRow() | rpl::start_with_next([=](Dialogs::ChosenRow row) {
if (const auto sublist = row.key.sublist()) { if (const auto sublist = row.key.sublist()) {
using namespace Window;
auto params = SectionShow(SectionShow::Way::Forward);
params.dropSameFromStack = true;
controller->showSection( controller->showSection(
std::make_shared<HistoryView::SublistMemento>(sublist), std::make_shared<HistoryView::SublistMemento>(sublist),
Window::SectionShow::Way::Forward); params);
} }
}, _list->lifetime()); }, _list->lifetime());

View file

@ -1379,7 +1379,7 @@ void MainWidget::showHistory(
if (!back && (way != Way::ClearStack)) { if (!back && (way != Way::ClearStack)) {
// This may modify the current section, for example remove its contents. // This may modify the current section, for example remove its contents.
saveSectionInStack(); saveSectionInStack(params);
} }
if (_history->peer() if (_history->peer()
@ -1501,13 +1501,23 @@ Ui::ChatTheme *MainWidget::customChatTheme() const {
return _history->customChatTheme(); return _history->customChatTheme();
} }
void MainWidget::saveSectionInStack() { bool MainWidget::saveSectionInStack(
const SectionShow &params,
Window::SectionWidget *newMainSection) {
if (_mainSection) { if (_mainSection) {
if (auto memento = _mainSection->createMemento()) { 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<StackItemSection>( _stack.push_back(std::make_unique<StackItemSection>(
std::move(memento))); std::move(memento)));
} else { } else {
return; return false;
} }
} else if (const auto history = _history->history()) { } else if (const auto history = _history->history()) {
_stack.push_back(std::make_unique<StackItemHistory>( _stack.push_back(std::make_unique<StackItemHistory>(
@ -1515,7 +1525,7 @@ void MainWidget::saveSectionInStack() {
_history->msgId(), _history->msgId(),
_history->replyReturns())); _history->replyReturns()));
} else { } else {
return; return false;
} }
const auto raw = _stack.back().get(); const auto raw = _stack.back().get();
raw->setThirdSectionWeak(_thirdSection.data()); raw->setThirdSectionWeak(_thirdSection.data());
@ -1528,6 +1538,7 @@ void MainWidget::saveSectionInStack() {
} }
} }
}, raw->lifetime()); }, raw->lifetime());
return true;
} }
void MainWidget::showSection( void MainWidget::showSection(
@ -1730,7 +1741,11 @@ void MainWidget::showNewSection(
if (saveInStack) { if (saveInStack) {
// This may modify the current section, for example remove its contents. // 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 auto &settingSection = newThirdSection
? _thirdSection ? _thirdSection

View file

@ -286,7 +286,9 @@ private:
Window::SectionSlideParams prepareHistoryAnimation(PeerId historyPeerId); Window::SectionSlideParams prepareHistoryAnimation(PeerId historyPeerId);
Window::SectionSlideParams prepareDialogsAnimation(); Window::SectionSlideParams prepareDialogsAnimation();
void saveSectionInStack(); bool saveSectionInStack(
const SectionShow &params,
Window::SectionWidget *newMainSection = nullptr);
int getMainSectionTop() const; int getMainSectionTop() const;
int getThirdSectionTop() const; int getThirdSectionTop() const;

View file

@ -138,6 +138,9 @@ public:
virtual bool showInternal( virtual bool showInternal(
not_null<SectionMemento*> memento, not_null<SectionMemento*> memento,
const SectionShow &params) = 0; const SectionShow &params) = 0;
virtual bool sameTypeAs(not_null<SectionMemento*> memento) {
return false;
}
virtual bool showMessage( virtual bool showMessage(
PeerId peerId, PeerId peerId,

View file

@ -162,6 +162,7 @@ struct SectionShow {
bool childColumn = false; bool childColumn = false;
bool forbidLayer = false; bool forbidLayer = false;
bool reapplyLocalDraft = false; bool reapplyLocalDraft = false;
bool dropSameFromStack = false;
Origin origin; Origin origin;
}; };