mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-17 22:57:11 +02:00
Support ?startapp=value start_param passing.
This commit is contained in:
parent
b17b806d91
commit
c12743925e
4 changed files with 49 additions and 25 deletions
|
@ -435,6 +435,8 @@ bool ResolveUsernameOrPhone(
|
|||
.attachBotUsername = params.value(u"attach"_q),
|
||||
.attachBotToggleCommand = (params.contains(u"startattach"_q)
|
||||
? params.value(u"startattach"_q)
|
||||
: (appname.isEmpty() && params.contains(u"startapp"_q))
|
||||
? params.value(u"startapp"_q)
|
||||
: std::optional<QString>()),
|
||||
.attachBotMenuOpen = (appname.isEmpty()
|
||||
&& params.contains(u"startapp"_q)),
|
||||
|
|
|
@ -878,7 +878,10 @@ void AttachWebView::cancel() {
|
|||
_startCommand = QString();
|
||||
}
|
||||
|
||||
void AttachWebView::requestBots() {
|
||||
void AttachWebView::requestBots(Fn<void()> callback) {
|
||||
if (callback) {
|
||||
_botsRequestCallbacks.push_back(std::move(callback));
|
||||
}
|
||||
if (_botsRequestId) {
|
||||
return;
|
||||
}
|
||||
|
@ -899,8 +902,14 @@ void AttachWebView::requestBots() {
|
|||
}
|
||||
_attachBotsUpdates.fire({});
|
||||
});
|
||||
for (const auto callback : base::take(_botsRequestCallbacks)) {
|
||||
callback();
|
||||
}
|
||||
}).fail([=] {
|
||||
_botsRequestId = 0;
|
||||
for (const auto callback : base::take(_botsRequestCallbacks)) {
|
||||
callback();
|
||||
}
|
||||
}).send();
|
||||
}
|
||||
|
||||
|
@ -998,8 +1007,12 @@ void AttachWebView::requestAddToMenu(
|
|||
return true;
|
||||
}
|
||||
} else if (v::is<AddToMenuOpenMenu>(open)) {
|
||||
const auto &openMenu = v::get<AddToMenuOpenMenu>(open);
|
||||
_bot = bot;
|
||||
requestSimple(strong, bot, { .fromMainMenu = true });
|
||||
requestSimple(strong, bot, {
|
||||
.startCommand = openMenu.startCommand,
|
||||
.fromMainMenu = true,
|
||||
});
|
||||
return true;
|
||||
} else if (const auto useTypes = chooseTypes & types) {
|
||||
const auto done = [=](not_null<Data::Thread*> thread) {
|
||||
|
@ -1127,9 +1140,7 @@ void AttachWebView::requestSimple(
|
|||
_context->fromSwitch = button.fromSwitch;
|
||||
_context->fromMainMenu = button.fromMainMenu;
|
||||
if (button.fromMainMenu) {
|
||||
acceptDisclaimer(controller, [=] {
|
||||
requestSimple(button);
|
||||
});
|
||||
acceptMainMenuDisclaimer(controller, button);
|
||||
} else {
|
||||
confirmOpen(controller, [=] {
|
||||
requestSimple(button);
|
||||
|
@ -1141,11 +1152,16 @@ void AttachWebView::requestSimple(const WebViewButton &button) {
|
|||
using Flag = MTPmessages_RequestSimpleWebView::Flag;
|
||||
_requestId = _session->api().request(MTPmessages_RequestSimpleWebView(
|
||||
MTP_flags(Flag::f_theme_params
|
||||
| (button.fromMainMenu ? Flag::f_from_side_menu : Flag::f_url)
|
||||
| (button.fromMainMenu
|
||||
? (Flag::f_from_side_menu
|
||||
| (button.startCommand.isEmpty()
|
||||
? Flag()
|
||||
: Flag::f_start_param))
|
||||
: Flag::f_url)
|
||||
| (button.fromSwitch ? Flag::f_from_switch_webview : Flag())),
|
||||
_bot->inputUser,
|
||||
MTP_bytes(button.url),
|
||||
MTP_string(""), // start_param
|
||||
MTP_string(button.startCommand),
|
||||
MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams().json)),
|
||||
MTP_string("tdesktop")
|
||||
)).done([=](const MTPSimpleWebViewResult &result) {
|
||||
|
@ -1360,9 +1376,11 @@ void AttachWebView::confirmOpen(
|
|||
}));
|
||||
}
|
||||
|
||||
void AttachWebView::acceptDisclaimer(
|
||||
void AttachWebView::acceptMainMenuDisclaimer(
|
||||
not_null<Window::SessionController*> controller,
|
||||
Fn<void()> done) {
|
||||
const WebViewButton &button) {
|
||||
Expects(button.fromMainMenu);
|
||||
|
||||
const auto local = _bot ? &_bot->session().local() : nullptr;
|
||||
if (!local) {
|
||||
return;
|
||||
|
@ -1375,10 +1393,12 @@ void AttachWebView::acceptDisclaimer(
|
|||
_attachBotsUpdates.fire({});
|
||||
return;
|
||||
} else if (i->inactive) {
|
||||
requestAddToMenu(_bot, AddToMenuOpenMenu(), controller, {});
|
||||
requestAddToMenu(_bot, AddToMenuOpenMenu{
|
||||
.startCommand = button.startCommand,
|
||||
}, controller, {});
|
||||
return;
|
||||
} else if (!i->disclaimerRequired || disclaimerAccepted(*i)) {
|
||||
done();
|
||||
requestSimple(button);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1386,7 +1406,7 @@ void AttachWebView::acceptDisclaimer(
|
|||
controller->show(Box(FillDisclaimerBox, crl::guard(this, [=] {
|
||||
_disclaimerAccepted.emplace(_bot);
|
||||
_attachBotsUpdates.fire({});
|
||||
done();
|
||||
requestSimple(button);
|
||||
})));
|
||||
}
|
||||
|
||||
|
@ -1593,10 +1613,8 @@ void AttachWebView::toggleInMenu(
|
|||
MTP_bool(state != ToggledState::Removed)
|
||||
)).done([=] {
|
||||
_requestId = 0;
|
||||
requestBots();
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
_session->api().request(base::take(_botsRequestId)).cancel();
|
||||
requestBots(std::move(callback));
|
||||
}).fail([=] {
|
||||
cancel();
|
||||
}).send();
|
||||
|
|
|
@ -75,6 +75,7 @@ struct AddToMenuOpenAttach {
|
|||
PeerTypes chooseTypes;
|
||||
};
|
||||
struct AddToMenuOpenMenu {
|
||||
QString startCommand;
|
||||
};
|
||||
struct AddToMenuOpenApp {
|
||||
not_null<BotAppData*> app;
|
||||
|
@ -127,7 +128,7 @@ public:
|
|||
|
||||
void cancel();
|
||||
|
||||
void requestBots();
|
||||
void requestBots(Fn<void()> callback = nullptr);
|
||||
[[nodiscard]] const std::vector<AttachWebViewBot> &attachBots() const {
|
||||
return _attachBots;
|
||||
}
|
||||
|
@ -196,9 +197,9 @@ private:
|
|||
void confirmOpen(
|
||||
not_null<Window::SessionController*> controller,
|
||||
Fn<void()> done);
|
||||
void acceptDisclaimer(
|
||||
void acceptMainMenuDisclaimer(
|
||||
not_null<Window::SessionController*> controller,
|
||||
Fn<void()> done);
|
||||
const WebViewButton &button);
|
||||
|
||||
enum class ToggledState {
|
||||
Removed,
|
||||
|
@ -251,6 +252,7 @@ private:
|
|||
|
||||
uint64 _botsHash = 0;
|
||||
mtpRequestId _botsRequestId = 0;
|
||||
std::vector<Fn<void()>> _botsRequestCallbacks;
|
||||
|
||||
std::unique_ptr<Context> _addToMenuContext;
|
||||
UserData *_addToMenuBot = nullptr;
|
||||
|
|
|
@ -578,6 +578,14 @@ void SessionNavigation::showPeerByLinkResolved(
|
|||
attachBotUsername,
|
||||
info.attachBotToggleCommand.value_or(QString()));
|
||||
});
|
||||
} else if (bot && info.attachBotMenuOpen) {
|
||||
const auto startCommand = info.attachBotToggleCommand.value_or(
|
||||
QString());
|
||||
bot->session().attachWebView().requestAddToMenu(
|
||||
bot,
|
||||
InlineBots::AddToMenuOpenMenu{ startCommand },
|
||||
parentController(),
|
||||
std::optional<Api::SendAction>());
|
||||
} else if (bot && info.attachBotToggleCommand) {
|
||||
const auto itemId = info.clickFromMessageId;
|
||||
const auto item = _session->data().message(itemId);
|
||||
|
@ -598,12 +606,6 @@ void SessionNavigation::showPeerByLinkResolved(
|
|||
? Api::SendAction(
|
||||
contextUser->owner().history(contextUser))
|
||||
: std::optional<Api::SendAction>()));
|
||||
} else if (bot && info.attachBotMenuOpen) {
|
||||
bot->session().attachWebView().requestAddToMenu(
|
||||
bot,
|
||||
InlineBots::AddToMenuOpenMenu(),
|
||||
parentController(),
|
||||
std::optional<Api::SendAction>());
|
||||
} else {
|
||||
crl::on_main(this, [=] {
|
||||
showPeerHistory(peer, params, msgId);
|
||||
|
|
Loading…
Add table
Reference in a new issue