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;
}
bool SublistWidget::sameTypeAs(not_null<Window::SectionMemento*> memento) {
return dynamic_cast<SublistMemento*>(memento.get()) != nullptr;
}
void SublistWidget::setInternalState(
const QRect &geometry,
not_null<SublistMemento*> memento) {

View File

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

View File

@ -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<HistoryView::SublistMemento>(sublist),
Window::SectionShow::Way::Forward);
params);
}
}, _list->lifetime());

View File

@ -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 &params,
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<StackItemSection>(
std::move(memento)));
} else {
return;
return false;
}
} else if (const auto history = _history->history()) {
_stack.push_back(std::make_unique<StackItemHistory>(
@ -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

View File

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

View File

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

View File

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