mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Simplified management of PasscodeBox within customCheckCallback.
This commit is contained in:
parent
1c223e570a
commit
d1be7c1ff7
6 changed files with 34 additions and 26 deletions
|
@ -236,14 +236,14 @@ void SendBotCallbackDataWithPassword(
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto box = std::make_shared<QPointer<PasscodeBox>>();
|
|
||||||
auto fields = PasscodeBox::CloudFields::From(state);
|
auto fields = PasscodeBox::CloudFields::From(state);
|
||||||
fields.customTitle = tr::lng_bots_password_confirm_title();
|
fields.customTitle = tr::lng_bots_password_confirm_title();
|
||||||
fields.customDescription
|
fields.customDescription
|
||||||
= tr::lng_bots_password_confirm_description(tr::now);
|
= tr::lng_bots_password_confirm_description(tr::now);
|
||||||
fields.customSubmitButton = tr::lng_passcode_submit();
|
fields.customSubmitButton = tr::lng_passcode_submit();
|
||||||
fields.customCheckCallback = [=](
|
fields.customCheckCallback = [=](
|
||||||
const Core::CloudPasswordResult &result) {
|
const Core::CloudPasswordResult &result,
|
||||||
|
QPointer<PasscodeBox> box) {
|
||||||
if (const auto button = getButton()) {
|
if (const auto button = getButton()) {
|
||||||
if (button->requestId) {
|
if (button->requestId) {
|
||||||
return;
|
return;
|
||||||
|
@ -257,18 +257,17 @@ void SendBotCallbackDataWithPassword(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SendBotCallbackData(strongController, item, row, column, result, [=] {
|
SendBotCallbackData(strongController, item, row, column, result, [=] {
|
||||||
if (*box) {
|
if (box) {
|
||||||
(*box)->closeBox();
|
box->closeBox();
|
||||||
}
|
}
|
||||||
}, [=](const QString &error) {
|
}, [=](const QString &error) {
|
||||||
if (*box) {
|
if (box) {
|
||||||
(*box)->handleCustomCheckError(error);
|
box->handleCustomCheckError(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
auto object = Box<PasscodeBox>(session, fields);
|
auto object = Box<PasscodeBox>(session, fields);
|
||||||
*box = Ui::MakeWeak(object.data());
|
|
||||||
show->showBox(std::move(object), Ui::LayerOption::CloseOther);
|
show->showBox(std::move(object), Ui::LayerOption::CloseOther);
|
||||||
}, *lifetime);
|
}, *lifetime);
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,19 +64,27 @@ void HandleWithdrawalButton(
|
||||||
= tr::lng_channel_earn_balance_password_description(tr::now);
|
= tr::lng_channel_earn_balance_password_description(tr::now);
|
||||||
fields.customSubmitButton = tr::lng_passcode_submit();
|
fields.customSubmitButton = tr::lng_passcode_submit();
|
||||||
fields.customCheckCallback = crl::guard(button, [=](
|
fields.customCheckCallback = crl::guard(button, [=](
|
||||||
const Core::CloudPasswordResult &result) {
|
const Core::CloudPasswordResult &result,
|
||||||
|
QPointer<PasscodeBox> box) {
|
||||||
|
const auto done = [=](const QString &result) {
|
||||||
|
if (!result.isEmpty()) {
|
||||||
|
UrlClickHandler::Open(result);
|
||||||
|
if (box) {
|
||||||
|
box->closeBox();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const auto fail = [=](const QString &error) {
|
||||||
|
show->showToast(error);
|
||||||
|
};
|
||||||
session->api().request(
|
session->api().request(
|
||||||
MTPstats_GetBroadcastRevenueWithdrawalUrl(
|
MTPstats_GetBroadcastRevenueWithdrawalUrl(
|
||||||
channel->inputChannel,
|
channel->inputChannel,
|
||||||
result.result
|
result.result
|
||||||
)).done([=](const MTPstats_BroadcastRevenueWithdrawalUrl &r) {
|
)).done([=](const MTPstats_BroadcastRevenueWithdrawalUrl &r) {
|
||||||
const auto url = qs(r.data().vurl());
|
done(qs(r.data().vurl()));
|
||||||
|
|
||||||
if (!url.isEmpty()) {
|
|
||||||
UrlClickHandler::Open(url);
|
|
||||||
}
|
|
||||||
}).fail([=](const MTP::Error &error) {
|
}).fail([=](const MTP::Error &error) {
|
||||||
show->showToast(error.type());
|
fail(error.type());
|
||||||
}).send();
|
}).send();
|
||||||
});
|
});
|
||||||
show->show(Box<PasscodeBox>(session, fields));
|
show->show(Box<PasscodeBox>(session, fields));
|
||||||
|
|
|
@ -740,7 +740,7 @@ void PasscodeBox::submitOnlyCheckCloudPassword(const QString &oldPassword) {
|
||||||
void PasscodeBox::sendOnlyCheckCloudPassword(const QString &oldPassword) {
|
void PasscodeBox::sendOnlyCheckCloudPassword(const QString &oldPassword) {
|
||||||
checkPassword(oldPassword, [=](const Core::CloudPasswordResult &check) {
|
checkPassword(oldPassword, [=](const Core::CloudPasswordResult &check) {
|
||||||
if (const auto onstack = _cloudFields.customCheckCallback) {
|
if (const auto onstack = _cloudFields.customCheckCallback) {
|
||||||
onstack(check);
|
onstack(check, Ui::MakeWeak(this));
|
||||||
} else {
|
} else {
|
||||||
Assert(_cloudFields.turningOff);
|
Assert(_cloudFields.turningOff);
|
||||||
sendClearCloudPassword(check);
|
sendClearCloudPassword(check);
|
||||||
|
|
|
@ -51,7 +51,10 @@ public:
|
||||||
TimeId pendingResetDate = 0;
|
TimeId pendingResetDate = 0;
|
||||||
|
|
||||||
// Check cloud password for some action.
|
// Check cloud password for some action.
|
||||||
Fn<void(const Core::CloudPasswordResult &)> customCheckCallback;
|
using CustomCheck = Fn<void(
|
||||||
|
const Core::CloudPasswordResult &,
|
||||||
|
QPointer<PasscodeBox>)>;
|
||||||
|
CustomCheck customCheckCallback;
|
||||||
rpl::producer<QString> customTitle;
|
rpl::producer<QString> customTitle;
|
||||||
std::optional<QString> customDescription;
|
std::optional<QString> customDescription;
|
||||||
rpl::producer<QString> customSubmitButton;
|
rpl::producer<QString> customSubmitButton;
|
||||||
|
|
|
@ -598,19 +598,17 @@ void EditAdminBox::requestTransferPassword(not_null<ChannelData*> channel) {
|
||||||
) | rpl::take(
|
) | rpl::take(
|
||||||
1
|
1
|
||||||
) | rpl::start_with_next([=](const Core::CloudPasswordState &state) {
|
) | rpl::start_with_next([=](const Core::CloudPasswordState &state) {
|
||||||
const auto box = std::make_shared<QPointer<PasscodeBox>>();
|
|
||||||
auto fields = PasscodeBox::CloudFields::From(state);
|
auto fields = PasscodeBox::CloudFields::From(state);
|
||||||
fields.customTitle = tr::lng_rights_transfer_password_title();
|
fields.customTitle = tr::lng_rights_transfer_password_title();
|
||||||
fields.customDescription
|
fields.customDescription
|
||||||
= tr::lng_rights_transfer_password_description(tr::now);
|
= tr::lng_rights_transfer_password_description(tr::now);
|
||||||
fields.customSubmitButton = tr::lng_passcode_submit();
|
fields.customSubmitButton = tr::lng_passcode_submit();
|
||||||
fields.customCheckCallback = crl::guard(this, [=](
|
fields.customCheckCallback = crl::guard(this, [=](
|
||||||
const Core::CloudPasswordResult &result) {
|
const Core::CloudPasswordResult &result,
|
||||||
sendTransferRequestFrom(*box, channel, result);
|
QPointer<PasscodeBox> box) {
|
||||||
|
sendTransferRequestFrom(box, channel, result);
|
||||||
});
|
});
|
||||||
*box = getDelegate()->show(Box<PasscodeBox>(
|
getDelegate()->show(Box<PasscodeBox>(&channel->session(), fields));
|
||||||
&channel->session(),
|
|
||||||
fields));
|
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -766,12 +766,12 @@ void CheckoutProcess::requestPassword() {
|
||||||
(index < list.size()) ? list[index].title : QString());
|
(index < list.size()) ? list[index].title : QString());
|
||||||
fields.customSubmitButton = tr::lng_payments_password_submit();
|
fields.customSubmitButton = tr::lng_payments_password_submit();
|
||||||
fields.customCheckCallback = [=](
|
fields.customCheckCallback = [=](
|
||||||
const Core::CloudPasswordResult &result) {
|
const Core::CloudPasswordResult &result,
|
||||||
|
QPointer<PasscodeBox> box) {
|
||||||
|
_enterPasswordBox = box;
|
||||||
_form->submit(result);
|
_form->submit(result);
|
||||||
};
|
};
|
||||||
auto owned = Box<PasscodeBox>(_session, fields);
|
_panel->showBox(Box<PasscodeBox>(_session, fields));
|
||||||
_enterPasswordBox = owned.data();
|
|
||||||
_panel->showBox(std::move(owned));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue