mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fix simple web view support.
This commit is contained in:
parent
c6ded00461
commit
a219cc43ce
3 changed files with 12 additions and 14 deletions
|
@ -235,7 +235,7 @@ void activateBotCommand(
|
||||||
if (const auto bot = msg->getMessageBot()) {
|
if (const auto bot = msg->getMessageBot()) {
|
||||||
bot->session().attachWebView().requestSimple(
|
bot->session().attachWebView().requestSimple(
|
||||||
bot,
|
bot,
|
||||||
button->data);
|
{ .text = button->text, .url = button->data });
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,7 +168,8 @@ void AttachWebView::resolveUsername(
|
||||||
if (error.code() == 400) {
|
if (error.code() == 400) {
|
||||||
Ui::ShowMultilineToast({
|
Ui::ShowMultilineToast({
|
||||||
.text = {
|
.text = {
|
||||||
tr::lng_username_not_found(tr::now, lt_user, username) }
|
tr::lng_username_not_found(tr::now, lt_user, username),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).send();
|
}).send();
|
||||||
|
@ -176,25 +177,21 @@ void AttachWebView::resolveUsername(
|
||||||
|
|
||||||
void AttachWebView::requestSimple(
|
void AttachWebView::requestSimple(
|
||||||
not_null<UserData*> bot,
|
not_null<UserData*> bot,
|
||||||
const QByteArray &url) {
|
const WebViewButton &button) {
|
||||||
if (_peer != bot || _bot != bot) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cancel();
|
cancel();
|
||||||
|
|
||||||
_bot = bot;
|
_bot = bot;
|
||||||
_peer = bot;
|
_peer = bot;
|
||||||
using Flag = MTPmessages_RequestSimpleWebView::Flag;
|
using Flag = MTPmessages_RequestSimpleWebView::Flag;
|
||||||
_requestId = _session->api().request(MTPmessages_RequestSimpleWebView(
|
_requestId = _session->api().request(MTPmessages_RequestSimpleWebView(
|
||||||
MTP_flags(0),
|
MTP_flags(Flag::f_theme_params),
|
||||||
bot->inputUser,
|
bot->inputUser,
|
||||||
MTP_bytes(url),
|
MTP_bytes(button.url),
|
||||||
MTPDataJSON()
|
MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams()))
|
||||||
)).done([=](const MTPSimpleWebViewResult &result) {
|
)).done([=](const MTPSimpleWebViewResult &result) {
|
||||||
_requestId = 0;
|
_requestId = 0;
|
||||||
result.match([&](const MTPDsimpleWebViewResultUrl &data) {
|
result.match([&](const MTPDsimpleWebViewResultUrl &data) {
|
||||||
const auto queryId = uint64();
|
const auto queryId = uint64();
|
||||||
show(queryId, qs(data.vurl()));
|
show(queryId, qs(data.vurl()), button.text);
|
||||||
});
|
});
|
||||||
}).fail([=](const MTP::Error &error) {
|
}).fail([=](const MTP::Error &error) {
|
||||||
_requestId = 0;
|
_requestId = 0;
|
||||||
|
@ -212,7 +209,7 @@ void AttachWebView::show(
|
||||||
cancel();
|
cancel();
|
||||||
});
|
});
|
||||||
const auto sendData = crl::guard(this, [=](QByteArray data) {
|
const auto sendData = crl::guard(this, [=](QByteArray data) {
|
||||||
if (_peer != _bot || !queryId) {
|
if (_peer != _bot) {
|
||||||
cancel();
|
cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,14 +32,15 @@ public:
|
||||||
struct WebViewButton {
|
struct WebViewButton {
|
||||||
QString text;
|
QString text;
|
||||||
QByteArray url;
|
QByteArray url;
|
||||||
bool simple = false;
|
|
||||||
};
|
};
|
||||||
void request(not_null<PeerData*> peer, const QString &botUsername);
|
void request(not_null<PeerData*> peer, const QString &botUsername);
|
||||||
void request(
|
void request(
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
not_null<UserData*> bot,
|
not_null<UserData*> bot,
|
||||||
const WebViewButton &button = WebViewButton());
|
const WebViewButton &button = WebViewButton());
|
||||||
void requestSimple(not_null<UserData*> bot, const QByteArray &url);
|
void requestSimple(
|
||||||
|
not_null<UserData*> bot,
|
||||||
|
const WebViewButton &button);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void cancel();
|
void cancel();
|
||||||
|
|
Loading…
Add table
Reference in a new issue