Fix possible crash in members invite.

In some cases Info::Controller (public Window::SessionNavigation)
can be destroyed without the box being destroyed, for example when
group topics are turned on and off.
This commit is contained in:
John Preston 2023-02-13 06:09:53 +04:00
parent 1cb0d7c2dc
commit 9d3715a36a

View file

@ -295,10 +295,11 @@ void AddParticipantsBoxController::Start(
not_null<ChatData*> chat) { not_null<ChatData*> chat) {
auto controller = std::make_unique<AddParticipantsBoxController>(chat); auto controller = std::make_unique<AddParticipantsBoxController>(chat);
const auto weak = controller.get(); const auto weak = controller.get();
const auto parent = navigation->parentController();
auto initBox = [=](not_null<PeerListBox*> box) { auto initBox = [=](not_null<PeerListBox*> box) {
box->addButton(tr::lng_participant_invite(), [=] { box->addButton(tr::lng_participant_invite(), [=] {
weak->inviteSelectedUsers(box, [=] { weak->inviteSelectedUsers(box, [=] {
navigation->parentController()->showPeerHistory( parent->showPeerHistory(
chat, chat,
Window::SectionShow::Way::ClearStack, Window::SectionShow::Way::ClearStack,
ShowAtTheEndMsgId); ShowAtTheEndMsgId);
@ -320,11 +321,12 @@ void AddParticipantsBoxController::Start(
channel, channel,
std::move(alreadyIn)); std::move(alreadyIn));
const auto weak = controller.get(); const auto weak = controller.get();
const auto parent = navigation->parentController();
auto initBox = [=](not_null<PeerListBox*> box) { auto initBox = [=](not_null<PeerListBox*> box) {
box->addButton(tr::lng_participant_invite(), [=] { box->addButton(tr::lng_participant_invite(), [=] {
weak->inviteSelectedUsers(box, [=] { weak->inviteSelectedUsers(box, [=] {
if (channel->isMegagroup()) { if (channel->isMegagroup()) {
navigation->parentController()->showPeerHistory( parent->showPeerHistory(
channel, channel,
Window::SectionShow::Way::ClearStack, Window::SectionShow::Way::ClearStack,
ShowAtTheEndMsgId); ShowAtTheEndMsgId);
@ -337,13 +339,16 @@ void AddParticipantsBoxController::Start(
justCreated ? tr::lng_create_group_skip() : tr::lng_cancel(), justCreated ? tr::lng_create_group_skip() : tr::lng_cancel(),
[=] { box->closeBox(); }); [=] { box->closeBox(); });
if (justCreated) { if (justCreated) {
const auto weak = base::make_weak(parent);
box->boxClosing() | rpl::start_with_next([=] { box->boxClosing() | rpl::start_with_next([=] {
auto params = Window::SectionShow(); auto params = Window::SectionShow();
params.activation = anim::activation::background; params.activation = anim::activation::background;
navigation->parentController()->showPeerHistory( if (const auto strong = weak.get()) {
channel, strong->showPeerHistory(
params, channel,
ShowAtTheEndMsgId); params,
ShowAtTheEndMsgId);
}
}, box->lifetime()); }, box->lifetime());
} }
}; };