diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index b27665ac88c579..0ba6354f996bd8 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -2200,8 +2200,11 @@ void Controller::saveForum() { channel->inputChannel, MTP_bool(*_savingData.forum) )).done([=](const MTPUpdates &result) { + const auto weak = base::make_weak(this); channel->session().api().applyUpdates(result); - continueSave(); + if (weak) { // todo better to be able to save in closed already box. + continueSave(); + } }).fail([=](const MTP::Error &error) { if (error.type() == u"CHAT_NOT_MODIFIED"_q) { continueSave(); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 45ad3ef62fd5b0..854441b8c21840 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1192,9 +1192,11 @@ void MainWidget::setInnerFocus() { _mainSection->setInnerFocus(); } else if (!_hider && _thirdSection) { _thirdSection->setInnerFocus(); - } else { - Assert(_dialogs != nullptr); + } else if (_dialogs) { _dialogs->setInnerFocus(); + } else { + // Maybe we're just closing a child window, content is destroyed. + _history->setFocus(); } } else if (_mainSection) { _mainSection->setInnerFocus(); @@ -1293,8 +1295,9 @@ void MainWidget::showHistory( } const auto unavailable = peer->computeUnavailableReason(); if (!unavailable.isEmpty()) { - Assert(isPrimary()); // windows todo - if (params.activation != anim::activation::background) { + if (!isPrimary()) { + _controller->window().close(); + } else if (params.activation != anim::activation::background) { _controller->show(Ui::MakeInformBox(unavailable)); _controller->window().activate(); } @@ -1950,10 +1953,9 @@ void MainWidget::showNonPremiumLimitToast(bool download) { }); } -void MainWidget::showBackFromStack( - const SectionShow ¶ms) { +bool MainWidget::showBackFromStack(const SectionShow ¶ms) { if (preventsCloseSection([=] { showBackFromStack(params); }, params)) { - return; + return false; } if (_stack.empty()) { @@ -1963,7 +1965,7 @@ void MainWidget::showBackFromStack( crl::on_main(this, [=] { _controller->widget()->setInnerFocus(); }); - return; + return (_dialogs != nullptr); } auto item = std::move(_stack.back()); _stack.pop_back(); @@ -1995,6 +1997,7 @@ void MainWidget::showBackFromStack( anim::activation::background)); } + return true; } void MainWidget::orderWidgets() { diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index b97c7f98fba950..7acbbead4e174c 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -152,8 +152,7 @@ class MainWidget final const SectionShow ¶ms); void updateColumnLayout(); bool stackIsEmpty() const; - void showBackFromStack( - const SectionShow ¶ms); + bool showBackFromStack(const SectionShow ¶ms); void orderWidgets(); QPixmap grabForShowAnimation(const Window::SectionSlideParams ¶ms); void checkMainSectionToLayer(); diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 017fb7fd0f445c..8380e458a10399 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -1660,8 +1660,9 @@ void SessionController::showForum( ) | rpl::start_with_next([=, history = forum->history()] { const auto now = activeChatCurrent().owningHistory(); const auto showHistory = !now || (now == history); + const auto weak = base::make_weak(this); closeForum(); - if (showHistory) { + if (weak && showHistory) { showPeerHistory(history, { SectionShow::Way::Backward, anim::type::normal, @@ -1676,7 +1677,7 @@ void SessionController::closeForum() { if (const auto forum = _shownForum.current()) { const auto id = windowId(); if (id.type == SeparateType::Forum) { - const auto initial = id.thread->asForum(); + const auto initial = id.forum(); if (!initial || initial == forum) { Core::App().closeWindow(_window); } else { @@ -2529,7 +2530,13 @@ void SessionController::showBackFromStack(const SectionShow ¶ms) { return topic && topic->forum()->topicDeleted(topic->rootId()); }; do { - content()->showBackFromStack(params); + const auto empty = content()->stackIsEmpty(); + const auto shown = content()->showBackFromStack(params); + if (empty && !shown && content()->stackIsEmpty() && bad()) { + clearSectionStack(anim::type::instant); + window().close(); + break; + } } while (bad()); }