mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Migrate games to AttachWebView.
This commit is contained in:
@@ -20,6 +20,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "history/history.h"
|
||||
#include "history/view/history_view_element.h"
|
||||
#include "history/history_item.h"
|
||||
#include "inline_bots/bot_attach_web_view.h"
|
||||
#include "data/data_game.h"
|
||||
#include "data/data_user.h"
|
||||
#include "data/data_session.h"
|
||||
#include "window/window_controller.h"
|
||||
@@ -171,23 +173,40 @@ void BotGameUrlClickHandler::onClick(ClickContext context) const {
|
||||
if (Core::InternalPassportLink(url)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto open = [=] {
|
||||
const auto openLink = [=] {
|
||||
UrlClickHandler::Open(url, context.other);
|
||||
};
|
||||
if (url.startsWith(u"tg://"_q, Qt::CaseInsensitive)) {
|
||||
open();
|
||||
} else if (!_bot
|
||||
|| _bot->isVerified()
|
||||
const auto my = context.other.value<ClickHandlerContext>();
|
||||
const auto weakController = my.sessionWindow;
|
||||
const auto controller = weakController.get();
|
||||
const auto item = controller
|
||||
? controller->session().data().message(my.itemId)
|
||||
: nullptr;
|
||||
const auto media = item ? item->media() : nullptr;
|
||||
const auto game = media ? media->game() : nullptr;
|
||||
if (url.startsWith(u"tg://"_q, Qt::CaseInsensitive) || !_bot || !game) {
|
||||
openLink();
|
||||
}
|
||||
const auto bot = _bot;
|
||||
const auto title = game->title;
|
||||
const auto itemId = my.itemId;
|
||||
const auto openGame = [=] {
|
||||
bot->session().attachWebView().showGame({
|
||||
.bot = bot,
|
||||
.context = itemId,
|
||||
.url = url,
|
||||
.title = title,
|
||||
});
|
||||
};
|
||||
if (_bot->isVerified()
|
||||
|| _bot->session().local().isBotTrustedOpenGame(_bot->id)) {
|
||||
open();
|
||||
openGame();
|
||||
} else {
|
||||
const auto my = context.other.value<ClickHandlerContext>();
|
||||
if (const auto controller = my.sessionWindow.get()) {
|
||||
const auto callback = [=, bot = _bot](Fn<void()> close) {
|
||||
close();
|
||||
bot->session().local().markBotTrustedOpenGame(bot->id);
|
||||
open();
|
||||
openGame();
|
||||
};
|
||||
controller->show(Ui::MakeConfirmBox({
|
||||
.text = tr::lng_allow_bot_pass(
|
||||
|
@@ -327,21 +327,6 @@ bool ConfirmPhone(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ShareGameScore(
|
||||
Window::SessionController *controller,
|
||||
const Match &match,
|
||||
const QVariant &context) {
|
||||
if (!controller) {
|
||||
return false;
|
||||
}
|
||||
const auto params = url_parse_params(
|
||||
match->captured(1),
|
||||
qthelp::UrlParamNameTransform::ToLower);
|
||||
ShareGameScoreByHash(controller, params.value(u"hash"_q));
|
||||
controller->window().activate();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ApplySocksProxy(
|
||||
Window::SessionController *controller,
|
||||
const Match &match,
|
||||
@@ -1230,10 +1215,6 @@ const std::vector<LocalUrlHandler> &LocalUrlHandlers() {
|
||||
u"^confirmphone/?\\?(.+)(#|$)"_q,
|
||||
ConfirmPhone
|
||||
},
|
||||
{
|
||||
u"^share_game_score/?\\?(.+)(#|$)"_q,
|
||||
ShareGameScore
|
||||
},
|
||||
{
|
||||
u"^socks/?\\?(.+)(#|$)"_q,
|
||||
ApplySocksProxy
|
||||
|
Reference in New Issue
Block a user