Fix possible crashes in toastParent expiring.

This commit is contained in:
John Preston 2022-12-07 13:03:13 +04:00
parent 6f50906952
commit cfddca8f58
8 changed files with 24 additions and 18 deletions

View file

@ -110,7 +110,9 @@ void SendBotCallbackData(
const auto showAlert = data.is_alert(); const auto showAlert = data.is_alert();
if (!message.isEmpty()) { if (!message.isEmpty()) {
if (showAlert) { if (!show->valid()) {
return;
} else if (showAlert) {
show->showBox(Ui::MakeInformBox(message)); show->showBox(Ui::MakeInformBox(message));
} else { } else {
if (withPassword) { if (withPassword) {

View file

@ -44,9 +44,10 @@ void SendReport(
Ui::ReportReason reason, Ui::ReportReason reason,
const QString &comment, const QString &comment,
std::variant<v::null_t, MessageIdsList, not_null<PhotoData*>> data) { std::variant<v::null_t, MessageIdsList, not_null<PhotoData*>> data) {
auto done = [=] { auto weak = Ui::MakeWeak(toastParent.get());
auto done = crl::guard(toastParent, [=] {
Ui::Toast::Show(toastParent, tr::lng_report_thanks(tr::now)); Ui::Toast::Show(toastParent, tr::lng_report_thanks(tr::now));
}; });
v::match(data, [&](v::null_t) { v::match(data, [&](v::null_t) {
peer->session().api().request(MTPaccount_ReportPeer( peer->session().api().request(MTPaccount_ReportPeer(
peer->input, peer->input,

View file

@ -622,21 +622,21 @@ void EditAdminBox::sendTransferRequestFrom(
channel->inputChannel, channel->inputChannel,
user->inputUser, user->inputUser,
result.result result.result
)).done([=, toastParent = _show.toastParent()](const MTPUpdates &result) { )).done([=](const MTPUpdates &result) {
api->applyUpdates(result); api->applyUpdates(result);
if (!box && !weak) {
return;
}
Ui::Toast::Show( Ui::Toast::Show(
toastParent, (box ? Ui::BoxShow(box) : weak->_show).toastParent(),
(channel->isBroadcast() (channel->isBroadcast()
? tr::lng_rights_transfer_done_channel ? tr::lng_rights_transfer_done_channel
: tr::lng_rights_transfer_done_group)( : tr::lng_rights_transfer_done_group)(
tr::now, tr::now,
lt_user, lt_user,
user->shortName())); user->shortName()));
if (box) { (box ? Ui::BoxShow(box) : weak->_show).hideLayer();
Ui::BoxShow(box).hideLayer();
} else if (weak) {
weak->_show.hideLayer();
}
}).fail(crl::guard(this, [=](const MTP::Error &error) { }).fail(crl::guard(this, [=](const MTP::Error &error) {
if (weak) { if (weak) {
_transferRequestId = 0; _transferRequestId = 0;

View file

@ -1438,6 +1438,7 @@ void StickerSetBox::Inner::install() {
} }
void StickerSetBox::Inner::archiveStickers() { void StickerSetBox::Inner::archiveStickers() {
const auto toastParent = Window::Show(_controller).toastParent();
_api.request(MTPmessages_InstallStickerSet( _api.request(MTPmessages_InstallStickerSet(
Data::InputStickerSet(_input), Data::InputStickerSet(_input),
MTP_boolTrue() MTP_boolTrue()
@ -1445,9 +1446,9 @@ void StickerSetBox::Inner::archiveStickers() {
if (result.type() == mtpc_messages_stickerSetInstallResultSuccess) { if (result.type() == mtpc_messages_stickerSetInstallResultSuccess) {
_setArchived.fire_copy(_setId); _setArchived.fire_copy(_setId);
} }
}).fail([toastParent = Window::Show(_controller).toastParent()] { }).fail(crl::guard(toastParent, [=] {
Ui::Toast::Show(toastParent, Lang::Hard::ServerError()); Ui::Toast::Show(toastParent, Lang::Hard::ServerError());
}).send(); })).send();
} }
void StickerSetBox::Inner::updateItems() { void StickerSetBox::Inner::updateItems() {

View file

@ -1209,11 +1209,11 @@ void AddSaveSoundForNotifications(
Api::ToggleSavedRingtone( Api::ToggleSavedRingtone(
document, document,
item->fullId(), item->fullId(),
[=] { crl::guard(toastParent, [=] {
Ui::Toast::Show( Ui::Toast::Show(
toastParent, toastParent,
tr::lng_ringtones_toast_added(tr::now)); tr::lng_ringtones_toast_added(tr::now));
}, }),
true); true);
}, &st::menuIconSoundAdd); }, &st::menuIconSoundAdd);
} }

View file

@ -202,7 +202,6 @@ void TTLBox(not_null<Ui::GenericBox*> box, Args args) {
if (args.startTtl && !args.hideDisable) { if (args.startTtl && !args.hideDisable) {
box->addLeftButton(tr::lng_manage_messages_ttl_disable(), [=] { box->addLeftButton(tr::lng_manage_messages_ttl_disable(), [=] {
args.callback(0, [=] { box->closeBox(); }); args.callback(0, [=] { box->closeBox(); });
box->getDelegate()->hideLayer();
}); });
} }
} }

View file

@ -68,7 +68,7 @@ Args TTLValidator::createArgs() const {
mtpRequestId savingRequestId = 0; mtpRequestId savingRequestId = 0;
}; };
const auto state = std::make_shared<State>(); const auto state = std::make_shared<State>();
auto callback = [=, toastParent = show->toastParent()]( auto callback = [=](
TimeId period, TimeId period,
Fn<void()>) { Fn<void()>) {
auto &api = peer->session().api(); auto &api = peer->session().api();
@ -79,12 +79,15 @@ Args TTLValidator::createArgs() const {
api.request(state->savingRequestId).cancel(); api.request(state->savingRequestId).cancel();
} }
state->savingPeriod = period; state->savingPeriod = period;
const auto weak = Ui::MakeWeak(show->toastParent().get());
state->savingRequestId = api.request(MTPmessages_SetHistoryTTL( state->savingRequestId = api.request(MTPmessages_SetHistoryTTL(
peer->input, peer->input,
MTP_int(period) MTP_int(period)
)).done([=](const MTPUpdates &result) { )).done([=](const MTPUpdates &result) {
peer->session().api().applyUpdates(result); peer->session().api().applyUpdates(result);
ShowAutoDeleteToast(toastParent, peer); if (const auto strong = weak.data()) {
ShowAutoDeleteToast(strong, peer);
}
state->savingRequestId = 0; state->savingRequestId = 0;
}).fail([=] { }).fail([=] {
state->savingRequestId = 0; state->savingRequestId = 0;

@ -1 +1 @@
Subproject commit d5921e742fa9f17f65a25091a184f5a8a72ea779 Subproject commit 580e6a561f7d252a94888b54c206e06ac0237c38