Skip to content

Commit

Permalink
Fix couple of crashes in secondary windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jul 2, 2024
1 parent 17bb430 commit ec2faca
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
5 changes: 4 additions & 1 deletion Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
19 changes: 11 additions & 8 deletions Telegram/SourceFiles/mainwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -1950,10 +1953,9 @@ void MainWidget::showNonPremiumLimitToast(bool download) {
});
}

void MainWidget::showBackFromStack(
const SectionShow &params) {
bool MainWidget::showBackFromStack(const SectionShow &params) {
if (preventsCloseSection([=] { showBackFromStack(params); }, params)) {
return;
return false;
}

if (_stack.empty()) {
Expand All @@ -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();
Expand Down Expand Up @@ -1995,6 +1997,7 @@ void MainWidget::showBackFromStack(
anim::activation::background));

}
return true;
}

void MainWidget::orderWidgets() {
Expand Down
3 changes: 1 addition & 2 deletions Telegram/SourceFiles/mainwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ class MainWidget final
const SectionShow &params);
void updateColumnLayout();
bool stackIsEmpty() const;
void showBackFromStack(
const SectionShow &params);
bool showBackFromStack(const SectionShow &params);
void orderWidgets();
QPixmap grabForShowAnimation(const Window::SectionSlideParams &params);
void checkMainSectionToLayer();
Expand Down
13 changes: 10 additions & 3 deletions Telegram/SourceFiles/window/window_session_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -2529,7 +2530,13 @@ void SessionController::showBackFromStack(const SectionShow &params) {
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());
}

Expand Down

0 comments on commit ec2faca

Please sign in to comment.