From c47f5e999524d8b19d9488593f8a2919d593f3a0 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 10 Sep 2024 13:37:19 +0300 Subject: [PATCH] Added ability to create box for share QR code without peer. --- .../info/profile/info_profile_actions.cpp | 10 ++-- Telegram/SourceFiles/ui/boxes/peer_qr_box.cpp | 46 +++++++++++-------- Telegram/SourceFiles/ui/boxes/peer_qr_box.h | 6 +-- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index e6ae95296..9df27a1b0 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -1127,9 +1127,8 @@ object_ptr DetailsFiller::setupInfo() { fitLabelToButton(copyUsername, usernameLine.text); copyUsername->setClickedCallback([=] { if (!user->isBot()) { - controller->show(Box([=](not_null box) { - Ui::FillPeerQrBox(box, user); - })); + controller->show( + Box(Ui::FillPeerQrBox, user, std::nullopt, nullptr)); return false; } const auto link = user->session().createInternalLinkFull( @@ -1209,9 +1208,8 @@ object_ptr DetailsFiller::setupInfo() { st::infoProfileLabeledButtonQr); fitLabelToButton(qr, linkLine.text); qr->setClickedCallback([=, peer = _peer] { - controller->show(Box([=](not_null box) { - Ui::FillPeerQrBox(box, peer); - })); + controller->show( + Box(Ui::FillPeerQrBox, peer, std::nullopt, nullptr)); return false; }); } diff --git a/Telegram/SourceFiles/ui/boxes/peer_qr_box.cpp b/Telegram/SourceFiles/ui/boxes/peer_qr_box.cpp index eb87f52e2..96c1b47ca 100644 --- a/Telegram/SourceFiles/ui/boxes/peer_qr_box.cpp +++ b/Telegram/SourceFiles/ui/boxes/peer_qr_box.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_cloud_themes.h" #include "data/data_peer.h" #include "data/data_session.h" +#include "data/data_user.h" #include "info/channel_statistics/boosts/giveaway/boost_badge.h" // InfiniteRadialAnimationWidget. #include "info/profile/info_profile_values.h" #include "lang/lang_keys.h" @@ -375,7 +376,7 @@ void Paint( void FillPeerQrBox( not_null box, - not_null peer, + PeerData *peer, std::optional customLink, rpl::producer about) { const auto window = Core::App().findWindow(box); @@ -400,6 +401,7 @@ void FillPeerQrBox( style::font font; }; const auto state = box->lifetime().make_state(); + state->userpicToggled = !(customLink || !peer); const auto createFont = [=](int scale) { return style::font( style::ConvertScale(30, scale), @@ -409,7 +411,7 @@ void FillPeerQrBox( state->font = createFont(style::Scale()); const auto usernameValue = [=] { - return customLink + return (customLink || !peer) ? rpl::single(QString()) : Info::Profile::UsernameValue(peer, true) | rpl::map( [](const auto &username) { return username.text; }); @@ -417,14 +419,17 @@ void FillPeerQrBox( const auto linkValue = [=] { return customLink ? rpl::single(*customLink) - : Info::Profile::LinkValue(peer, true) | rpl::map( - [](const auto &link) { return link.text; }); + : peer + ? Info::Profile::LinkValue(peer, true) | rpl::map( + [](const auto &link) { return link.text; }) + : rpl::single(QString()); }; const auto userpic = Ui::CreateChild( box, - peer, + peer ? peer : controller->session().user().get(), st::defaultUserpicButton); + userpic->setVisible(peer != nullptr); const auto qr = PrepareQrWidget( box->verticalLayout(), userpic, @@ -696,19 +701,21 @@ void FillPeerQrBox( } Ui::AddSkip(box->verticalLayout()); Ui::AddSkip(box->verticalLayout()); - const auto userpicToggle = box->verticalLayout()->add( - object_ptr( - box->verticalLayout(), - (peer->isUser() - ? tr::lng_mediaview_profile_photo - : (peer->isChannel() && !peer->isMegagroup()) - ? tr::lng_mediaview_channel_photo - : tr::lng_mediaview_group_photo)(), - st::settingsButtonNoIcon)); - userpicToggle->toggleOn(state->userpicToggled.value(), true); - userpicToggle->setClickedCallback([=] { - state->userpicToggled = !state->userpicToggled.current(); - }); + if (peer) { + const auto userpicToggle = box->verticalLayout()->add( + object_ptr( + box->verticalLayout(), + (peer->isUser() + ? tr::lng_mediaview_profile_photo + : (peer->isChannel() && !peer->isMegagroup()) + ? tr::lng_mediaview_channel_photo + : tr::lng_mediaview_group_photo)(), + st::settingsButtonNoIcon)); + userpicToggle->toggleOn(state->userpicToggled.value(), true); + userpicToggle->setClickedCallback([=] { + state->userpicToggled = !state->userpicToggled.current(); + }); + } Ui::AddSkip(box->verticalLayout()); Ui::AddSkip(box->verticalLayout()); @@ -718,6 +725,9 @@ void FillPeerQrBox( tr::lng_chat_link_copy()); const auto show = controller->uiShow(); state->saveButton = box->addButton(std::move(buttonText), [=] { + if (state->saveButtonBusy.current()) { + return; + } const auto buttonWidth = state->saveButton ? state->saveButton->width() : 0; diff --git a/Telegram/SourceFiles/ui/boxes/peer_qr_box.h b/Telegram/SourceFiles/ui/boxes/peer_qr_box.h index 6bbad4c81..043447ce4 100644 --- a/Telegram/SourceFiles/ui/boxes/peer_qr_box.h +++ b/Telegram/SourceFiles/ui/boxes/peer_qr_box.h @@ -15,8 +15,8 @@ class GenericBox; void FillPeerQrBox( not_null box, - not_null peer, - std::optional customLink = std::nullopt, - rpl::producer about = nullptr); + PeerData *peer, + std::optional customLink, + rpl::producer about); } // namespace Ui