From 5a55e850d94b4b29a616d47e6ae945b6250332cf Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 30 Oct 2023 15:06:12 +0300 Subject: [PATCH] Added subtext to list of giftcode options in giveaway box. --- Telegram/Resources/langs/lang.strings | 2 - .../info/boosts/create_giveaway_box.cpp | 53 +++++++++++++++---- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index b8e1b160b..75e3d31ca 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2100,8 +2100,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_giveaway_duration_title#one" = "Duration of Premium subscription"; "lng_giveaway_duration_title#other" = "Duration of Premium subscriptions"; "lng_giveaway_duration_price" = "{price} x {amount}"; -"lng_giveaway_duration_about" = "You can review the list of features and terms of use for Telegram Premium {link}."; -"lng_giveaway_duration_about_link" = "here"; "lng_giveaway_date_select" = "Select Date and Time"; "lng_giveaway_date_confirm" = "Confirm"; "lng_giveaway_channels_select#one" = "Select up to {count} channel"; diff --git a/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp b/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp index 8d6987378..d85cd6201 100644 --- a/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp +++ b/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp @@ -16,12 +16,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/info_controller.h" #include "lang/lang_keys.h" #include "settings/settings_common.h" +#include "settings/settings_premium.h" // Settings::ShowPremium #include "ui/effects/premium_graphics.h" #include "ui/layers/generic_box.h" +#include "ui/text/text_utilities.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/labels.h" #include "styles/style_layers.h" #include "styles/style_premium.h" +#include "styles/style_settings.h" namespace { @@ -63,6 +66,8 @@ void CreateGiveawayBox( not_null box, not_null controller, not_null peer) { + using GiveawayType = Giveaway::GiveawayTypeRow::Type; + using GiveawayGroup = Ui::RadioenumGroup; struct State final { State(not_null p) : apiOptions(p) { } @@ -72,10 +77,10 @@ void CreateGiveawayBox( std::vector> selectedToAward; rpl::event_stream<> toAwardAmountChanged; + + rpl::variable typeValue; }; const auto state = box->lifetime().make_state(peer); - using GiveawayType = Giveaway::GiveawayTypeRow::Type; - using GiveawayGroup = Ui::RadioenumGroup; const auto typeGroup = std::make_shared(); box->setWidth(st::boxWideWidth); @@ -88,7 +93,7 @@ void CreateGiveawayBox( tr::lng_giveaway_create_subtitle())); row->addRadio(typeGroup); row->setClickedCallback([=] { - typeGroup->setValue(GiveawayType::Random); + state->typeValue.force_assign(GiveawayType::Random); }); } { @@ -122,9 +127,10 @@ void CreateGiveawayBox( }); peersBox->boxClosing( ) | rpl::start_with_next([=] { - typeGroup->setValue(state->selectedToAward.empty() - ? GiveawayType::Random - : GiveawayType::SpecificUsers); + state->typeValue.force_assign( + state->selectedToAward.empty() + ? GiveawayType::Random + : GiveawayType::SpecificUsers); }, peersBox->lifetime()); }; @@ -138,30 +144,56 @@ void CreateGiveawayBox( Ui::LayerOption::KeepOther); }); } - typeGroup->setValue(GiveawayType::Random); Settings::AddSkip(box->verticalLayout()); Settings::AddDivider(box->verticalLayout()); Settings::AddSkip(box->verticalLayout()); + const auto durationGroup = std::make_shared(0); { const auto listOptions = box->verticalLayout()->add( object_ptr(box)); - const auto durationGroup = std::make_shared(0); const auto rebuildListOptions = [=](int amountUsers) { while (listOptions->count()) { delete listOptions->widgetAt(0); } + Settings::AddSubsectionTitle( + listOptions, + tr::lng_giveaway_duration_title( + lt_count, + rpl::single(amountUsers) | tr::to_count())); Ui::Premium::AddGiftOptions( listOptions, durationGroup, state->apiOptions.options(amountUsers), st::giveawayGiftCodeGiftOption, true); + + auto terms = object_ptr( + listOptions, + tr::lng_premium_gift_terms( + lt_link, + tr::lng_premium_gift_terms_link( + ) | rpl::map([](const QString &t) { + return Ui::Text::Link(t, 1); + }), + Ui::Text::WithEntities), + st::boxDividerLabel); + terms->setLink(1, std::make_shared([=] { + box->closeBox(); + Settings::ShowPremium(&peer->session(), QString()); + })); + listOptions->add(object_ptr( + listOptions, + std::move(terms), + st::settingsDividerLabelPadding)); + listOptions->resizeToWidth(box->width()); }; - typeGroup->setChangedCallback([=](GiveawayType type) { + state->typeValue.value( + ) | rpl::start_with_next([=](GiveawayType type) { + typeGroup->setValue(type); const auto rebuild = [=] { rebuildListOptions((type == GiveawayType::SpecificUsers) ? state->selectedToAward.size() @@ -174,13 +206,14 @@ void CreateGiveawayBox( } else { rebuild(); } - }); + }, box->lifetime()); state->lifetimeApi = state->apiOptions.request( ) | rpl::start_with_error_done([=](const QString &error) { }, [=] { rebuildListOptions(1); }); } + state->typeValue.force_assign(GiveawayType::Random); box->addButton(tr::lng_box_ok(), [=] { box->closeBox();