Fix simple web view support.

This commit is contained in:
John Preston 2022-03-29 13:21:10 +04:00
parent c6ded00461
commit a219cc43ce
3 changed files with 12 additions and 14 deletions

View file

@ -235,7 +235,7 @@ void activateBotCommand(
if (const auto bot = msg->getMessageBot()) {
bot->session().attachWebView().requestSimple(
bot,
button->data);
{ .text = button->text, .url = button->data });
}
} break;
}

View file

@ -168,7 +168,8 @@ void AttachWebView::resolveUsername(
if (error.code() == 400) {
Ui::ShowMultilineToast({
.text = {
tr::lng_username_not_found(tr::now, lt_user, username) }
tr::lng_username_not_found(tr::now, lt_user, username),
},
});
}
}).send();
@ -176,25 +177,21 @@ void AttachWebView::resolveUsername(
void AttachWebView::requestSimple(
not_null<UserData*> bot,
const QByteArray &url) {
if (_peer != bot || _bot != bot) {
return;
}
const WebViewButton &button) {
cancel();
_bot = bot;
_peer = bot;
using Flag = MTPmessages_RequestSimpleWebView::Flag;
_requestId = _session->api().request(MTPmessages_RequestSimpleWebView(
MTP_flags(0),
MTP_flags(Flag::f_theme_params),
bot->inputUser,
MTP_bytes(url),
MTPDataJSON()
MTP_bytes(button.url),
MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams()))
)).done([=](const MTPSimpleWebViewResult &result) {
_requestId = 0;
result.match([&](const MTPDsimpleWebViewResultUrl &data) {
const auto queryId = uint64();
show(queryId, qs(data.vurl()));
show(queryId, qs(data.vurl()), button.text);
});
}).fail([=](const MTP::Error &error) {
_requestId = 0;
@ -212,7 +209,7 @@ void AttachWebView::show(
cancel();
});
const auto sendData = crl::guard(this, [=](QByteArray data) {
if (_peer != _bot || !queryId) {
if (_peer != _bot) {
cancel();
return;
}

View file

@ -32,14 +32,15 @@ public:
struct WebViewButton {
QString text;
QByteArray url;
bool simple = false;
};
void request(not_null<PeerData*> peer, const QString &botUsername);
void request(
not_null<PeerData*> peer,
not_null<UserData*> bot,
const WebViewButton &button = WebViewButton());
void requestSimple(not_null<UserData*> bot, const QByteArray &url);
void requestSimple(
not_null<UserData*> bot,
const WebViewButton &button);
private:
void cancel();