Fix couple of crashes in secondary windows.

This commit is contained in:
John Preston 2024-07-02 18:08:24 +04:00
parent 17bb430006
commit ec2faca145
4 changed files with 26 additions and 14 deletions

View file

@ -2200,8 +2200,11 @@ void Controller::saveForum() {
channel->inputChannel, channel->inputChannel,
MTP_bool(*_savingData.forum) MTP_bool(*_savingData.forum)
)).done([=](const MTPUpdates &result) { )).done([=](const MTPUpdates &result) {
const auto weak = base::make_weak(this);
channel->session().api().applyUpdates(result); channel->session().api().applyUpdates(result);
if (weak) { // todo better to be able to save in closed already box.
continueSave(); continueSave();
}
}).fail([=](const MTP::Error &error) { }).fail([=](const MTP::Error &error) {
if (error.type() == u"CHAT_NOT_MODIFIED"_q) { if (error.type() == u"CHAT_NOT_MODIFIED"_q) {
continueSave(); continueSave();

View file

@ -1192,9 +1192,11 @@ void MainWidget::setInnerFocus() {
_mainSection->setInnerFocus(); _mainSection->setInnerFocus();
} else if (!_hider && _thirdSection) { } else if (!_hider && _thirdSection) {
_thirdSection->setInnerFocus(); _thirdSection->setInnerFocus();
} else { } else if (_dialogs) {
Assert(_dialogs != nullptr);
_dialogs->setInnerFocus(); _dialogs->setInnerFocus();
} else {
// Maybe we're just closing a child window, content is destroyed.
_history->setFocus();
} }
} else if (_mainSection) { } else if (_mainSection) {
_mainSection->setInnerFocus(); _mainSection->setInnerFocus();
@ -1293,8 +1295,9 @@ void MainWidget::showHistory(
} }
const auto unavailable = peer->computeUnavailableReason(); const auto unavailable = peer->computeUnavailableReason();
if (!unavailable.isEmpty()) { if (!unavailable.isEmpty()) {
Assert(isPrimary()); // windows todo if (!isPrimary()) {
if (params.activation != anim::activation::background) { _controller->window().close();
} else if (params.activation != anim::activation::background) {
_controller->show(Ui::MakeInformBox(unavailable)); _controller->show(Ui::MakeInformBox(unavailable));
_controller->window().activate(); _controller->window().activate();
} }
@ -1950,10 +1953,9 @@ void MainWidget::showNonPremiumLimitToast(bool download) {
}); });
} }
void MainWidget::showBackFromStack( bool MainWidget::showBackFromStack(const SectionShow &params) {
const SectionShow &params) {
if (preventsCloseSection([=] { showBackFromStack(params); }, params)) { if (preventsCloseSection([=] { showBackFromStack(params); }, params)) {
return; return false;
} }
if (_stack.empty()) { if (_stack.empty()) {
@ -1963,7 +1965,7 @@ void MainWidget::showBackFromStack(
crl::on_main(this, [=] { crl::on_main(this, [=] {
_controller->widget()->setInnerFocus(); _controller->widget()->setInnerFocus();
}); });
return; return (_dialogs != nullptr);
} }
auto item = std::move(_stack.back()); auto item = std::move(_stack.back());
_stack.pop_back(); _stack.pop_back();
@ -1995,6 +1997,7 @@ void MainWidget::showBackFromStack(
anim::activation::background)); anim::activation::background));
} }
return true;
} }
void MainWidget::orderWidgets() { void MainWidget::orderWidgets() {

View file

@ -152,8 +152,7 @@ public:
const SectionShow &params); const SectionShow &params);
void updateColumnLayout(); void updateColumnLayout();
bool stackIsEmpty() const; bool stackIsEmpty() const;
void showBackFromStack( bool showBackFromStack(const SectionShow &params);
const SectionShow &params);
void orderWidgets(); void orderWidgets();
QPixmap grabForShowAnimation(const Window::SectionSlideParams &params); QPixmap grabForShowAnimation(const Window::SectionSlideParams &params);
void checkMainSectionToLayer(); void checkMainSectionToLayer();

View file

@ -1660,8 +1660,9 @@ void SessionController::showForum(
) | rpl::start_with_next([=, history = forum->history()] { ) | rpl::start_with_next([=, history = forum->history()] {
const auto now = activeChatCurrent().owningHistory(); const auto now = activeChatCurrent().owningHistory();
const auto showHistory = !now || (now == history); const auto showHistory = !now || (now == history);
const auto weak = base::make_weak(this);
closeForum(); closeForum();
if (showHistory) { if (weak && showHistory) {
showPeerHistory(history, { showPeerHistory(history, {
SectionShow::Way::Backward, SectionShow::Way::Backward,
anim::type::normal, anim::type::normal,
@ -1676,7 +1677,7 @@ void SessionController::closeForum() {
if (const auto forum = _shownForum.current()) { if (const auto forum = _shownForum.current()) {
const auto id = windowId(); const auto id = windowId();
if (id.type == SeparateType::Forum) { if (id.type == SeparateType::Forum) {
const auto initial = id.thread->asForum(); const auto initial = id.forum();
if (!initial || initial == forum) { if (!initial || initial == forum) {
Core::App().closeWindow(_window); Core::App().closeWindow(_window);
} else { } else {
@ -2529,7 +2530,13 @@ void SessionController::showBackFromStack(const SectionShow &params) {
return topic && topic->forum()->topicDeleted(topic->rootId()); return topic && topic->forum()->topicDeleted(topic->rootId());
}; };
do { 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()); } while (bad());
} }