mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 14:45:14 +00:00
Update API scheme on layer 140.
This commit is contained in:
@@ -47,6 +47,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "core/core_settings.h"
|
||||
#include "core/click_handler_types.h"
|
||||
#include "base/unixtime.h"
|
||||
#include "base/random.h"
|
||||
#include "ui/layers/generic_box.h"
|
||||
#include "ui/text/text_utilities.h"
|
||||
#include "ui/text/format_values.h" // Ui::FormatPhone.
|
||||
@@ -61,7 +62,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "ui/toasts/common_toasts.h"
|
||||
#include "calls/calls_instance.h" // Core::App().calls().inCall().
|
||||
#include "calls/group/calls_group_call.h"
|
||||
#include "inline_bots/inline_bot_result.h"
|
||||
#include "ui/boxes/calendar_box.h"
|
||||
#include "ui/boxes/confirm_box.h"
|
||||
#include "mainwidget.h"
|
||||
@@ -430,24 +430,29 @@ void SessionNavigation::resolveAttachWebview(
|
||||
void SessionNavigation::requestAttachWebview(
|
||||
not_null<PeerData*> peer,
|
||||
not_null<UserData*> bot,
|
||||
const QByteArray &url) {
|
||||
const WebViewButton &button) {
|
||||
using Flag = MTPmessages_RequestWebView::Flag;
|
||||
_api.request(MTPmessages_RequestWebView(
|
||||
MTP_flags(url.isEmpty() ? Flag(0) : Flag::f_url),
|
||||
MTP_flags(button.url.isEmpty() ? Flag(0) : Flag::f_url),
|
||||
peer->input,
|
||||
bot->inputUser,
|
||||
MTP_bytes(url),
|
||||
MTPDataJSON() // theme_params
|
||||
MTP_bytes(button.url),
|
||||
MTPDataJSON(), // theme_params
|
||||
MTPint() // reply_to_msg_id
|
||||
)).done([=](const MTPWebViewResult &result) {
|
||||
result.match([&](const MTPDwebViewResultUrl &data) {
|
||||
const auto url = qs(data.vurl());
|
||||
showAttachWebview(peer, bot, data.vquery_id().v, url);
|
||||
showAttachWebview(
|
||||
peer,
|
||||
bot,
|
||||
data.vquery_id().v,
|
||||
qs(data.vurl()),
|
||||
button.text);
|
||||
}, [&](const MTPDwebViewResultConfirmationRequired &data) {
|
||||
session().data().processUsers(data.vusers());
|
||||
const auto &received = data.vbot();
|
||||
if (const auto bot = ParseAttachBot(&session(), received)) {
|
||||
requestAddToMenu(bot, [=] {
|
||||
requestAttachWebview(peer, bot);
|
||||
requestAttachWebview(peer, bot, button);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -456,40 +461,53 @@ void SessionNavigation::requestAttachWebview(
|
||||
}).send();
|
||||
}
|
||||
|
||||
void SessionNavigation::requestAttachSimpleWebview(
|
||||
not_null<UserData*> bot,
|
||||
const QByteArray &url) {
|
||||
using Flag = MTPmessages_RequestSimpleWebView::Flag;
|
||||
_api.request(MTPmessages_RequestSimpleWebView(
|
||||
MTP_flags(0),
|
||||
bot->inputUser,
|
||||
MTP_bytes(url),
|
||||
MTPDataJSON()
|
||||
)).done([=](const MTPSimpleWebViewResult &result) {
|
||||
result.match([&](const MTPDsimpleWebViewResultUrl &data) {
|
||||
const auto queryId = uint64();
|
||||
showAttachWebview(bot, bot, queryId, qs(data.vurl()));
|
||||
});
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
int a = error.code();
|
||||
}).send();
|
||||
}
|
||||
|
||||
void SessionNavigation::showAttachWebview(
|
||||
not_null<PeerData*> peer,
|
||||
not_null<UserData*> bot,
|
||||
uint64 queryId,
|
||||
const QString &url) {
|
||||
const QString &url,
|
||||
const QString &buttonText) {
|
||||
const auto close = crl::guard(this, [=] {
|
||||
_botWebView = nullptr;
|
||||
});
|
||||
const auto send = crl::guard(this, [=] {
|
||||
_api.request(MTPmessages_GetWebViewResult(
|
||||
peer->input,
|
||||
const auto sendData = crl::guard(this, [=](QByteArray data) {
|
||||
if (peer != bot || !queryId) {
|
||||
return;
|
||||
}
|
||||
const auto randomId = base::RandomValue<uint64>();
|
||||
const auto api = &session().api();
|
||||
api->request(MTPmessages_SendWebViewData(
|
||||
bot->inputUser,
|
||||
MTP_long(queryId)
|
||||
)).done([=](const MTPmessages_WebViewResult &result) {
|
||||
result.match([&](const MTPDmessages_webViewResult &data) {
|
||||
session().data().processUsers(data.vusers());
|
||||
auto result = InlineBots::Result::Create(
|
||||
&session(),
|
||||
queryId,
|
||||
data.vresult());
|
||||
_inlineResultConfirmed.fire({
|
||||
.result = result.get(),
|
||||
.bot = bot,
|
||||
.recipientOverride = peer,
|
||||
//.options =
|
||||
});
|
||||
close();
|
||||
});
|
||||
MTP_long(randomId),
|
||||
MTP_string(buttonText),
|
||||
MTP_bytes(data)
|
||||
)).done([=](const MTPUpdates &result) {
|
||||
api->applyUpdates(result);
|
||||
}).send();
|
||||
});
|
||||
_botWebView = Ui::BotWebView::Show({
|
||||
.url = url,
|
||||
.userDataPath = session().domain().local().webviewDataPath(),
|
||||
.send = send,
|
||||
.sendData = sendData,
|
||||
.close = close,
|
||||
});
|
||||
}
|
||||
@@ -521,11 +539,6 @@ void SessionNavigation::toggleInMenu(
|
||||
}).send();
|
||||
}
|
||||
|
||||
auto SessionNavigation::inlineResultConfirmed() const
|
||||
-> rpl::producer<InlineBots::ResultSelected> {
|
||||
return _inlineResultConfirmed.events();
|
||||
}
|
||||
|
||||
void SessionNavigation::showRepliesForMessage(
|
||||
not_null<History*> history,
|
||||
MsgId rootId,
|
||||
|
@@ -65,10 +65,6 @@ namespace Ui::BotWebView {
|
||||
class Panel;
|
||||
} // namespace Ui::BotWebView
|
||||
|
||||
namespace InlineBots {
|
||||
struct ResultSelected;
|
||||
} // namespace InlineBots
|
||||
|
||||
namespace Data {
|
||||
struct CloudTheme;
|
||||
enum class CloudThemeType;
|
||||
@@ -205,15 +201,21 @@ public:
|
||||
};
|
||||
void showPeerByLink(const PeerByLinkInfo &info);
|
||||
|
||||
struct WebViewButton {
|
||||
QString text;
|
||||
QByteArray url;
|
||||
bool simple = false;
|
||||
};
|
||||
void resolveAttachWebview(
|
||||
not_null<PeerData*> peer,
|
||||
const QString &botUsername);
|
||||
void requestAttachWebview(
|
||||
not_null<PeerData*> peer,
|
||||
not_null<UserData*> bot,
|
||||
const QByteArray &url = QByteArray());
|
||||
[[nodiscard]] auto inlineResultConfirmed() const
|
||||
-> rpl::producer<InlineBots::ResultSelected>;
|
||||
const WebViewButton &button = WebViewButton());
|
||||
void requestAttachSimpleWebview(
|
||||
not_null<UserData*> bot,
|
||||
const QByteArray &url);
|
||||
|
||||
void showRepliesForMessage(
|
||||
not_null<History*> history,
|
||||
@@ -287,7 +289,8 @@ private:
|
||||
not_null<PeerData*> peer,
|
||||
not_null<UserData*> bot,
|
||||
uint64 queryId,
|
||||
const QString &url);
|
||||
const QString &url,
|
||||
const QString &buttonText = QString());
|
||||
|
||||
void toggleInMenu(
|
||||
not_null<UserData*> bot,
|
||||
@@ -305,7 +308,6 @@ private:
|
||||
mtpRequestId _showingRepliesRequestId = 0;
|
||||
|
||||
std::unique_ptr<Ui::BotWebView::Panel> _botWebView;
|
||||
rpl::event_stream<InlineBots::ResultSelected> _inlineResultConfirmed;
|
||||
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user