From cf1d274b0dc1a42a0a59a9a32a3cc0a604cce17a Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 30 Sep 2024 12:18:48 +0400 Subject: [PATCH] Return gift_credits_box with gifting stars. --- Telegram/CMakeLists.txt | 2 + .../SourceFiles/boxes/gift_credits_box.cpp | 181 ++++++++++++++++++ Telegram/SourceFiles/boxes/gift_credits_box.h | 20 ++ Telegram/SourceFiles/boxes/star_gift_box.cpp | 14 +- Telegram/SourceFiles/boxes/star_gift_box.h | 6 +- .../SourceFiles/core/local_url_handlers.cpp | 2 +- .../info/profile/info_profile_actions.cpp | 2 +- .../SourceFiles/settings/settings_credits.cpp | 3 +- .../SourceFiles/settings/settings_main.cpp | 2 +- .../SourceFiles/window/window_peer_menu.cpp | 2 +- 10 files changed, 216 insertions(+), 18 deletions(-) create mode 100644 Telegram/SourceFiles/boxes/gift_credits_box.cpp create mode 100644 Telegram/SourceFiles/boxes/gift_credits_box.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 716421792..f378d925a 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -276,6 +276,8 @@ PRIVATE boxes/edit_caption_box.h boxes/edit_privacy_box.cpp boxes/edit_privacy_box.h + boxes/gift_credits_box.cpp + boxes/gift_credits_box.h boxes/gift_premium_box.cpp boxes/gift_premium_box.h boxes/language_box.cpp diff --git a/Telegram/SourceFiles/boxes/gift_credits_box.cpp b/Telegram/SourceFiles/boxes/gift_credits_box.cpp new file mode 100644 index 000000000..f0ecd05f6 --- /dev/null +++ b/Telegram/SourceFiles/boxes/gift_credits_box.cpp @@ -0,0 +1,181 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "boxes/gift_credits_box.h" + +#include "api/api_credits.h" +#include "boxes/peer_list_controllers.h" +#include "data/data_peer.h" +#include "data/data_session.h" +#include "data/data_user.h" +#include "data/stickers/data_custom_emoji.h" +#include "lang/lang_keys.h" +#include "main/session/session_show.h" +#include "settings/settings_credits_graphics.h" +#include "ui/controls/userpic_button.h" +#include "ui/effects/premium_graphics.h" +#include "ui/effects/premium_stars_colored.h" +#include "ui/layers/generic_box.h" +#include "ui/rect.h" +#include "ui/text/text_utilities.h" +#include "ui/vertical_list.h" +#include "ui/widgets/label_with_custom_emoji.h" +#include "window/window_session_controller.h" +#include "styles/style_boxes.h" +#include "styles/style_channel_earn.h" +#include "styles/style_chat.h" +#include "styles/style_credits.h" +#include "styles/style_giveaway.h" +#include "styles/style_layers.h" +#include "styles/style_premium.h" + +namespace Ui { + +void GiftCreditsBox( + not_null box, + not_null peer, + Fn gifted) { + box->setWidth(st::boxWideWidth); + box->setStyle(st::creditsGiftBox); + box->setNoContentMargin(true); + box->addButton(tr::lng_create_group_back(), [=] { box->closeBox(); }); + + const auto content = box->setPinnedToTopContent( + object_ptr(box)); + + Ui::AddSkip(content); + Ui::AddSkip(content); + const auto &stUser = st::premiumGiftsUserpicButton; + const auto userpicWrap = content->add( + object_ptr>( + content, + object_ptr(content, peer, stUser))); + userpicWrap->setAttribute(Qt::WA_TransparentForMouseEvents); + Ui::AddSkip(content); + Ui::AddSkip(content); + + { + const auto widget = Ui::CreateChild(content); + using ColoredMiniStars = Ui::Premium::ColoredMiniStars; + const auto stars = widget->lifetime().make_state( + widget, + false, + Ui::Premium::MiniStars::Type::BiStars); + stars->setColorOverride(Ui::Premium::CreditsIconGradientStops()); + widget->resize( + st::boxWidth - stUser.photoSize, + stUser.photoSize * 2); + content->sizeValue( + ) | rpl::start_with_next([=](const QSize &size) { + widget->moveToLeft(stUser.photoSize / 2, 0); + const auto starsRect = Rect(widget->size()); + stars->setPosition(starsRect.topLeft()); + stars->setSize(starsRect.size()); + widget->lower(); + }, widget->lifetime()); + widget->paintRequest( + ) | rpl::start_with_next([=](const QRect &r) { + auto p = QPainter(widget); + p.fillRect(r, Qt::transparent); + stars->paint(p); + }, widget->lifetime()); + } + { + Ui::AddSkip(content); + const auto arrow = Ui::Text::SingleCustomEmoji( + peer->owner().customEmojiManager().registerInternalEmoji( + st::topicButtonArrow, + st::channelEarnLearnArrowMargins, + false)); + auto link = tr::lng_credits_box_history_entry_gift_about_link( + lt_emoji, + rpl::single(arrow), + Ui::Text::RichLangValue + ) | rpl::map([](TextWithEntities text) { + return Ui::Text::Link( + std::move(text), + u"internal:stars_examples"_q); + }); + content->add( + object_ptr>( + content, + Ui::CreateLabelWithCustomEmoji( + content, + tr::lng_credits_box_history_entry_gift_out_about( + lt_user, + rpl::single(TextWithEntities{ peer->shortName() }), + lt_link, + std::move(link), + Ui::Text::RichLangValue), + { .session = &peer->session() }, + st::creditsBoxAbout)), + st::boxRowPadding); + } + Ui::AddSkip(content); + Ui::AddSkip(box->verticalLayout()); + + Settings::FillCreditOptions( + Main::MakeSessionShow(box->uiShow(), &peer->session()), + box->verticalLayout(), + peer, + 0, + [=] { gifted(); box->uiShow()->hideLayer(); }); + + box->setPinnedToBottomContent( + object_ptr(box)); +} + +void ShowGiftCreditsBox( + not_null controller, + Fn gifted) { + + class Controller final : public ContactsBoxController { + public: + Controller( + not_null session, + Fn)> choose) + : ContactsBoxController(session) + , _choose(std::move(choose)) { + } + + protected: + std::unique_ptr createRow( + not_null user) override { + if (user->isSelf() + || user->isBot() + || user->isServiceUser() + || user->isInaccessible()) { + return nullptr; + } + return ContactsBoxController::createRow(user); + } + + void rowClicked(not_null row) override { + _choose(row->peer()); + } + + private: + const Fn)> _choose; + + }; + auto initBox = [=](not_null peersBox) { + peersBox->setTitle(tr::lng_credits_gift_title()); + peersBox->addButton(tr::lng_cancel(), [=] { peersBox->closeBox(); }); + }; + + const auto show = controller->uiShow(); + auto listController = std::make_unique( + &controller->session(), + [=](not_null peer) { + show->showBox(Box(GiftCreditsBox, peer, gifted)); + }); + show->showBox( + Box(std::move(listController), std::move(initBox)), + Ui::LayerOption::KeepOther); +} + +} // namespace Ui diff --git a/Telegram/SourceFiles/boxes/gift_credits_box.h b/Telegram/SourceFiles/boxes/gift_credits_box.h new file mode 100644 index 000000000..43b8556f3 --- /dev/null +++ b/Telegram/SourceFiles/boxes/gift_credits_box.h @@ -0,0 +1,20 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +namespace Window { +class SessionController; +} // namespace Window + +namespace Ui { + +void ShowGiftCreditsBox( + not_null controller, + Fn gifted); + +} // namespace Ui diff --git a/Telegram/SourceFiles/boxes/star_gift_box.cpp b/Telegram/SourceFiles/boxes/star_gift_box.cpp index 93f651cca..50a3a34e7 100644 --- a/Telegram/SourceFiles/boxes/star_gift_box.cpp +++ b/Telegram/SourceFiles/boxes/star_gift_box.cpp @@ -1168,8 +1168,7 @@ void AddBlock( void GiftBox( not_null box, not_null window, - not_null peer, - Fn gifted) { + not_null peer) { box->setWidth(st::boxWideWidth); box->setStyle(st::creditsGiftBox); box->setNoContentMargin(true); @@ -1255,9 +1254,7 @@ void GiftBox( } // namespace void ChooseStarGiftRecipient( - not_null controller, - Fn gifted) { - + not_null controller) { class Controller final : public ContactsBoxController { public: Controller( @@ -1295,7 +1292,7 @@ void ChooseStarGiftRecipient( auto listController = std::make_unique( &controller->session(), [=](not_null peer) { - ShowStarGiftBox(controller, peer, gifted); + ShowStarGiftBox(controller, peer); }); controller->show( Box(std::move(listController), std::move(initBox)), @@ -1304,9 +1301,8 @@ void ChooseStarGiftRecipient( void ShowStarGiftBox( not_null controller, - not_null peer, - Fn gifted) { - controller->show(Box(GiftBox, controller, peer, gifted)); + not_null peer) { + controller->show(Box(GiftBox, controller, peer)); } } // namespace Ui diff --git a/Telegram/SourceFiles/boxes/star_gift_box.h b/Telegram/SourceFiles/boxes/star_gift_box.h index eadd64b93..e1ae249a3 100644 --- a/Telegram/SourceFiles/boxes/star_gift_box.h +++ b/Telegram/SourceFiles/boxes/star_gift_box.h @@ -14,12 +14,10 @@ class SessionController; namespace Ui { void ChooseStarGiftRecipient( - not_null controller, - Fn gifted); + not_null controller); void ShowStarGiftBox( not_null controller, - not_null peer, - Fn gifted); + not_null peer); } // namespace Ui diff --git a/Telegram/SourceFiles/core/local_url_handlers.cpp b/Telegram/SourceFiles/core/local_url_handlers.cpp index 1ef7cf083..910d291e9 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -1133,7 +1133,7 @@ bool ResolvePremiumMultigift( if (!controller) { return false; } - Ui::ChooseStarGiftRecipient(controller, [] {}); + Ui::ChooseStarGiftRecipient(controller); controller->window().activate(); return true; } diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 091b2a7bf..94b034d0a 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -706,7 +706,7 @@ base::options::toggle ShowPeerIdBelowAbout({ button->setClickedCallback([=] { if (!button->isDisabled()) { - Ui::ShowStarGiftBox(controller, user, [] {}); + Ui::ShowStarGiftBox(controller, user); } }); diff --git a/Telegram/SourceFiles/settings/settings_credits.cpp b/Telegram/SourceFiles/settings/settings_credits.cpp index a3d58c39a..b36f1df0f 100644 --- a/Telegram/SourceFiles/settings/settings_credits.cpp +++ b/Telegram/SourceFiles/settings/settings_credits.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_credits.h" #include "boxes/star_gift_box.h" +#include "boxes/gift_credits_box.h" #include "boxes/gift_premium_box.h" #include "core/click_handler_types.h" #include "data/components/credits.h" @@ -360,7 +361,7 @@ void Credits::setupContent() { Ui::AddSkip(content); Ui::AddDivider(content); giftButton->setClickedCallback([=] { - Ui::ChooseStarGiftRecipient(_controller, paid); + Ui::ShowGiftCreditsBox(_controller, paid); }); } diff --git a/Telegram/SourceFiles/settings/settings_main.cpp b/Telegram/SourceFiles/settings/settings_main.cpp index f05fe7b97..685f3ae57 100644 --- a/Telegram/SourceFiles/settings/settings_main.cpp +++ b/Telegram/SourceFiles/settings/settings_main.cpp @@ -528,7 +528,7 @@ void SetupPremium( { .icon = &st::menuIconGiftPremium } ); button->addClickHandler([=] { - Ui::ChooseStarGiftRecipient(controller, [] {}); + Ui::ChooseStarGiftRecipient(controller); }); } Ui::AddSkip(container); diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index f334fb09b..00df587bc 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -1240,7 +1240,7 @@ void Filler::addGiftPremium() { const auto navigation = _controller; _addAction(tr::lng_profile_gift_premium(tr::now), [=] { - Ui::ChooseStarGiftRecipient(navigation, [] {}); + Ui::ChooseStarGiftRecipient(navigation); }, &st::menuIconGiftPremium); }