diff --git a/Telegram/SourceFiles/info/info_controller.cpp b/Telegram/SourceFiles/info/info_controller.cpp index 799ca59e02..bde22cd812 100644 --- a/Telegram/SourceFiles/info/info_controller.cpp +++ b/Telegram/SourceFiles/info/info_controller.cpp @@ -290,6 +290,10 @@ void Controller::showBackFromStack(const Window::SectionShow ¶ms) { } } +void Controller::removeFromStack(const std::vector
§ions) const { + _widget->removeFromStack(sections); +} + auto Controller::produceSearchQuery( const QString &query) const -> SearchQuery { Expects(_key.peer() != nullptr); diff --git a/Telegram/SourceFiles/info/info_controller.h b/Telegram/SourceFiles/info/info_controller.h index 3f0294fb85..10a38a7abf 100644 --- a/Telegram/SourceFiles/info/info_controller.h +++ b/Telegram/SourceFiles/info/info_controller.h @@ -212,6 +212,8 @@ public: void showBackFromStack( const Window::SectionShow ¶ms = Window::SectionShow()) override; + void removeFromStack(const std::vector
§ions) const; + rpl::lifetime &lifetime() { return _lifetime; } @@ -240,4 +242,4 @@ private: }; -} // namespace Info \ No newline at end of file +} // namespace Info diff --git a/Telegram/SourceFiles/info/info_wrap_widget.cpp b/Telegram/SourceFiles/info/info_wrap_widget.cpp index e5c389998c..5fc532606d 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.cpp +++ b/Telegram/SourceFiles/info/info_wrap_widget.cpp @@ -596,6 +596,26 @@ bool WrapWidget::showBackFromStackInternal( return (wrap() == Wrap::Layer); } +void WrapWidget::removeFromStack(const std::vector
§ions) { + for (const auto §ion : sections) { + const auto it = ranges::find_if(_historyStack, [&]( + const StackItem &item) { + const auto &s = item.section->section(); + if (s.type() != section.type()) { + return false; + } else if (s.type() == Section::Type::Media) { + return (s.mediaType() == section.mediaType()); + } else if (s.type() == Section::Type::Settings) { + return (s.settingsType() == section.settingsType()); + } + return false; + }); + if (it != end(_historyStack)) { + _historyStack.erase(it); + } + } +} + not_null WrapWidget::topWidget() const { // This was done for tabs support. // diff --git a/Telegram/SourceFiles/info/info_wrap_widget.h b/Telegram/SourceFiles/info/info_wrap_widget.h index 8c53558312..d2cf6c2ca6 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.h +++ b/Telegram/SourceFiles/info/info_wrap_widget.h @@ -106,6 +106,7 @@ public: not_null memento, const Window::SectionShow ¶ms) override; bool showBackFromStackInternal(const Window::SectionShow ¶ms); + void removeFromStack(const std::vector
§ions); std::shared_ptr createMemento() override; rpl::producer desiredHeightValue() const override; diff --git a/Telegram/SourceFiles/info/settings/info_settings_widget.cpp b/Telegram/SourceFiles/info/settings/info_settings_widget.cpp index dcd02d2039..d20d5490f0 100644 --- a/Telegram/SourceFiles/info/settings/info_settings_widget.cpp +++ b/Telegram/SourceFiles/info/settings/info_settings_widget.cpp @@ -59,6 +59,16 @@ Widget::Widget( controller->showBackFromStack(); }, _inner->lifetime()); + _removesFromStack.events( + ) | rpl::start_with_next([=](const std::vector &types) { + const auto sections = ranges::views::all( + types + ) | ranges::views::transform([](Type type) { + return Section(type); + }) | ranges::to_vector; + controller->removeFromStack(sections); + }, _inner->lifetime()); + if (_pinnedToTop) { _inner->widthValue( ) | rpl::start_with_next([=](int w) { @@ -104,6 +114,9 @@ void Widget::saveChanges(FnMut done) { void Widget::showFinished() { _inner->showFinished(); + + _inner->removeFromStack( + ) | rpl::start_to_stream(_removesFromStack, lifetime()); } void Widget::setInnerFocus() { diff --git a/Telegram/SourceFiles/info/settings/info_settings_widget.h b/Telegram/SourceFiles/info/settings/info_settings_widget.h index 0f4e9fd3a5..d6de4287d3 100644 --- a/Telegram/SourceFiles/info/settings/info_settings_widget.h +++ b/Telegram/SourceFiles/info/settings/info_settings_widget.h @@ -84,6 +84,8 @@ private: not_null<::Settings::AbstractSection*> _inner; QPointer _pinnedToTop; + rpl::event_stream> _removesFromStack; + }; } // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_common.h b/Telegram/SourceFiles/settings/settings_common.h index 27f48cec32..03566fdfb3 100644 --- a/Telegram/SourceFiles/settings/settings_common.h +++ b/Telegram/SourceFiles/settings/settings_common.h @@ -81,6 +81,9 @@ public: [[nodiscard]] virtual rpl::producer<> sectionShowBack() { return nullptr; } + [[nodiscard]] virtual rpl::producer> removeFromStack() { + return nullptr; + } [[nodiscard]] virtual rpl::producer title() = 0; virtual void sectionSaveChanges(FnMut done) { done();