mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 13:17:08 +02:00
Don't confirm each bot-url webapp open.
This commit is contained in:
parent
5309138980
commit
03b6e2df17
2 changed files with 32 additions and 8 deletions
|
@ -946,7 +946,12 @@ void WebViewInstance::resolve() {
|
||||||
requestSimple();
|
requestSimple();
|
||||||
});
|
});
|
||||||
}, [&](WebViewSourceLinkApp data) {
|
}, [&](WebViewSourceLinkApp data) {
|
||||||
resolveApp(data.appname, data.token, !_context.maySkipConfirmation);
|
resolveApp(
|
||||||
|
data.appname,
|
||||||
|
data.token,
|
||||||
|
(_context.maySkipConfirmation
|
||||||
|
? ConfirmType::None
|
||||||
|
: ConfirmType::Always));
|
||||||
}, [&](WebViewSourceLinkBotProfile) {
|
}, [&](WebViewSourceLinkBotProfile) {
|
||||||
confirmOpen([=] {
|
confirmOpen([=] {
|
||||||
requestMain();
|
requestMain();
|
||||||
|
@ -994,14 +999,14 @@ bool WebViewInstance::openAppFromBotMenuLink() {
|
||||||
if (appname.isEmpty()) {
|
if (appname.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
resolveApp(appname, params.value(u"startapp"_q), true);
|
resolveApp(appname, params.value(u"startapp"_q), ConfirmType::Once);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebViewInstance::resolveApp(
|
void WebViewInstance::resolveApp(
|
||||||
const QString &appname,
|
const QString &appname,
|
||||||
const QString &startparam,
|
const QString &startparam,
|
||||||
bool forceConfirmation) {
|
ConfirmType confirmType) {
|
||||||
const auto already = _session->data().findBotApp(_bot->id, appname);
|
const auto already = _session->data().findBotApp(_bot->id, appname);
|
||||||
_requestId = _session->api().request(MTPmessages_GetBotApp(
|
_requestId = _session->api().request(MTPmessages_GetBotApp(
|
||||||
MTP_inputBotAppShortName(
|
MTP_inputBotAppShortName(
|
||||||
|
@ -1021,8 +1026,11 @@ void WebViewInstance::resolveApp(
|
||||||
close();
|
close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto confirm = data.is_inactive() || forceConfirmation;
|
const auto confirm = data.is_inactive()
|
||||||
|
|| (confirmType != ConfirmType::None);
|
||||||
const auto writeAccess = result.data().is_request_write_access();
|
const auto writeAccess = result.data().is_request_write_access();
|
||||||
|
const auto forceConfirmation = data.is_inactive()
|
||||||
|
|| (confirmType == ConfirmType::Always);
|
||||||
|
|
||||||
// Check if this app can be added to main menu.
|
// Check if this app can be added to main menu.
|
||||||
// On fail it'll still be opened.
|
// On fail it'll still be opened.
|
||||||
|
@ -1035,7 +1043,7 @@ void WebViewInstance::resolveApp(
|
||||||
} else if (confirm) {
|
} else if (confirm) {
|
||||||
confirmAppOpen(writeAccess, [=](bool allowWrite) {
|
confirmAppOpen(writeAccess, [=](bool allowWrite) {
|
||||||
requestApp(allowWrite);
|
requestApp(allowWrite);
|
||||||
});
|
}, forceConfirmation);
|
||||||
} else {
|
} else {
|
||||||
requestApp(false);
|
requestApp(false);
|
||||||
}
|
}
|
||||||
|
@ -1082,10 +1090,18 @@ void WebViewInstance::confirmOpen(Fn<void()> done) {
|
||||||
|
|
||||||
void WebViewInstance::confirmAppOpen(
|
void WebViewInstance::confirmAppOpen(
|
||||||
bool writeAccess,
|
bool writeAccess,
|
||||||
Fn<void(bool allowWrite)> done) {
|
Fn<void(bool allowWrite)> done,
|
||||||
|
bool forceConfirmation) {
|
||||||
|
if (!forceConfirmation
|
||||||
|
&& (_bot->isVerified()
|
||||||
|
|| _session->local().isBotTrustedOpenWebView(_bot->id))) {
|
||||||
|
done(writeAccess);
|
||||||
|
return;
|
||||||
|
}
|
||||||
_parentShow->show(Box([=](not_null<Ui::GenericBox*> box) {
|
_parentShow->show(Box([=](not_null<Ui::GenericBox*> box) {
|
||||||
const auto allowed = std::make_shared<Ui::Checkbox*>();
|
const auto allowed = std::make_shared<Ui::Checkbox*>();
|
||||||
const auto callback = [=](Fn<void()> close) {
|
const auto callback = [=](Fn<void()> close) {
|
||||||
|
_session->local().markBotTrustedOpenWebView(_bot->id);
|
||||||
done((*allowed) && (*allowed)->checked());
|
done((*allowed) && (*allowed)->checked());
|
||||||
close();
|
close();
|
||||||
};
|
};
|
||||||
|
|
|
@ -230,12 +230,20 @@ private:
|
||||||
void requestWithMenuAdd();
|
void requestWithMenuAdd();
|
||||||
void maybeChooseAndRequestButton(PeerTypes supported);
|
void maybeChooseAndRequestButton(PeerTypes supported);
|
||||||
|
|
||||||
|
enum class ConfirmType : uchar {
|
||||||
|
Always,
|
||||||
|
Once,
|
||||||
|
None,
|
||||||
|
};
|
||||||
void resolveApp(
|
void resolveApp(
|
||||||
const QString &appname,
|
const QString &appname,
|
||||||
const QString &startparam,
|
const QString &startparam,
|
||||||
bool forceConfirmation);
|
ConfirmType confirmType);
|
||||||
void confirmOpen(Fn<void()> done);
|
void confirmOpen(Fn<void()> done);
|
||||||
void confirmAppOpen(bool writeAccess, Fn<void(bool allowWrite)> done);
|
void confirmAppOpen(
|
||||||
|
bool writeAccess,
|
||||||
|
Fn<void(bool allowWrite)> done,
|
||||||
|
bool forceConfirmation);
|
||||||
|
|
||||||
struct ShowArgs {
|
struct ShowArgs {
|
||||||
QString url;
|
QString url;
|
||||||
|
|
Loading…
Add table
Reference in a new issue