From 649d242e9abfc1f545784f94f42443cf84602148 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 3 Oct 2024 20:06:51 +0300 Subject: [PATCH] Added userpic of web view bots to box of confirmation to open. --- Telegram/Resources/langs/lang.strings | 1 - .../inline_bots/bot_attach_web_view.cpp | 108 +++++++++--------- 2 files changed, 57 insertions(+), 52 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 27f129a39..d4cd32e52 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -3315,7 +3315,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_allow_bot" = "Allow"; "lng_allow_bot_webview_details" = "More about this bot {emoji}"; "lng_allow_bot_webview_details_about" = "To launch this web app, you will connect to its website.\n\nIt will be able to access your **IP address** and basic device info."; -"lng_allow_bot_webview" = "{bot_name} would like to open its web app to proceed.\n\nIt will be able to access your **IP address** and basic device info."; "lng_url_auth_open_confirm" = "Do you want to open {link}?"; "lng_url_auth_login_option" = "Log in to {domain} as {user}"; "lng_url_auth_allow_messages" = "Allow {bot} to send me messages"; diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp index 8d9512c05..8daa1006b 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp @@ -361,6 +361,52 @@ WebViewContext ResolveContext( return context; } +void FillBotUsepic( + not_null box, + not_null bot, + base::weak_ptr weak) { + auto arrow = Ui::Text::SingleCustomEmoji( + bot->owner().customEmojiManager().registerInternalEmoji( + st::topicButtonArrow, + st::channelEarnLearnArrowMargins, + false)); + auto aboutLabel = Ui::CreateLabelWithCustomEmoji( + box->verticalLayout(), + tr::lng_allow_bot_webview_details( + lt_emoji, + rpl::single(std::move(arrow)), + Ui::Text::RichLangValue + ) | rpl::map([](TextWithEntities text) { + return Ui::Text::Link(std::move(text), u"internal:"_q); + }), + { .session = &bot->session() }, + st::defaultFlatLabel); + const auto userpic = Ui::CreateChild( + box->verticalLayout(), + bot, + st::mainMenuUserpic); + Ui::AddSkip(box->verticalLayout()); + aboutLabel->setClickHandlerFilter([=]( + const ClickHandlerPtr &, + Qt::MouseButton) { + if (const auto strong = weak.get()) { + strong->showPeerHistory( + bot->id, + Window::SectionShow::Way::Forward); + return true; + } + return false; + }); + Ui::IconWithTitle( + box->verticalLayout(), + userpic, + Ui::CreateChild( + box->verticalLayout(), + rpl::single(bot->name()), + box->getDelegate()->style().title), + aboutLabel); +} + class BotAction final : public Ui::Menu::ItemBase { public: BotAction( @@ -775,15 +821,16 @@ void WebViewInstance::confirmOpen(Fn done) { botClose(); close(); }; - _parentShow->show(Ui::MakeConfirmBox({ - .text = tr::lng_allow_bot_webview( - tr::now, - lt_bot_name, - Ui::Text::Bold(_bot->name()), - Ui::Text::RichLangValue), - .confirmed = crl::guard(this, callback), - .cancelled = crl::guard(this, cancel), - .confirmText = tr::lng_box_ok(), + _parentShow->show(Box([=](not_null box) { + FillBotUsepic(box, _bot, _context.controller); + Ui::ConfirmBox(box, { + .text = tr::lng_allow_bot_webview_details_about( + tr::now, + Ui::Text::RichLangValue), + .confirmed = crl::guard(this, callback), + .cancelled = crl::guard(this, cancel), + .confirmText = tr::lng_box_ok(), + }); })); } @@ -800,48 +847,7 @@ void WebViewInstance::confirmAppOpen( botClose(); close(); }; - { - auto arrow = Ui::Text::SingleCustomEmoji( - _bot->owner().customEmojiManager().registerInternalEmoji( - st::topicButtonArrow, - st::channelEarnLearnArrowMargins, - false)); - auto aboutLabel = Ui::CreateLabelWithCustomEmoji( - box->verticalLayout(), - tr::lng_allow_bot_webview_details( - lt_emoji, - rpl::single(std::move(arrow)), - Ui::Text::RichLangValue - ) | rpl::map([](TextWithEntities text) { - return Ui::Text::Link(std::move(text), u"internal:"_q); - }), - { .session = &_bot->session() }, - st::defaultFlatLabel); - const auto userpic = Ui::CreateChild( - box->verticalLayout(), - _bot, - st::mainMenuUserpic); - Ui::AddSkip(box->verticalLayout()); - aboutLabel->setClickHandlerFilter([=, weak = _context.controller]( - const ClickHandlerPtr &, - Qt::MouseButton) { - if (const auto strong = weak.get()) { - strong->showPeerHistory( - _bot->id, - Window::SectionShow::Way::Forward); - return true; - } - return false; - }); - Ui::IconWithTitle( - box->verticalLayout(), - userpic, - Ui::CreateChild( - box->verticalLayout(), - rpl::single(_bot->name()), - box->getDelegate()->style().title), - aboutLabel); - } + FillBotUsepic(box, _bot, _context.controller); Ui::ConfirmBox(box, { tr::lng_allow_bot_webview_details_about( tr::now,