From 85fdc04d48ba930bfc4b7ac325537eb1f7cc9d4d Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 1 Nov 2023 01:13:03 +0300 Subject: [PATCH] Added ability to create giveaways from giveaway box. --- .../info/boosts/create_giveaway_box.cpp | 45 ++++++++++++++----- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp b/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp index 52f5c7283c..abd739e9d3 100644 --- a/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp +++ b/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_premium.h" #include "base/call_delayed.h" #include "base/unixtime.h" +#include "countries/countries_instance.h" #include "data/data_peer.h" #include "info/boosts/giveaway/giveaway_list_controllers.h" #include "info/boosts/giveaway/giveaway_type_row.h" @@ -521,13 +522,21 @@ void CreateGiveawayBox( if (state->confirmButtonBusy) { return; } - if (typeGroup->value() == GiveawayType::SpecificUsers) { + const auto type = typeGroup->value(); + const auto isSpecific = (type == GiveawayType::SpecificUsers); + const auto isRandom = (type == GiveawayType::Random); + if (!isSpecific && !isRandom) { + return; + } + auto invoice = state->apiOptions.invoice( + isSpecific + ? state->selectedToAward.size() + : state->sliderValue.current(), + durationGroup->value()); + if (isSpecific) { if (state->selectedToAward.empty()) { return; } - auto invoice = state->apiOptions.invoice( - state->selectedToAward.size(), - durationGroup->value()); invoice.purpose = Payments::InvoicePremiumGiftCodeUsers{ ranges::views::all( state->selectedToAward @@ -537,14 +546,28 @@ void CreateGiveawayBox( }) | ranges::to_vector, peer->asChannel(), }; - state->confirmButtonBusy = true; - Payments::CheckoutProcess::Start( - std::move(invoice), - crl::guard(box, [=](auto) { - state->confirmButtonBusy = false; - box->window()->setFocus(); - })); + } else if (isRandom) { + invoice.purpose = Payments::InvoicePremiumGiftCodeGiveaway{ + .boostPeer = peer->asChannel(), + .additionalChannels = ranges::views::all( + state->selectedToSubscribe + ) | ranges::views::transform([]( + const not_null p) { + return not_null{ p->asChannel() }; + }) | ranges::to_vector, + .countries = state->countriesValue.current(), + .untilDate = state->dateValue.current(), + .onlyNewSubscribers = (membersGroup->value() + == GiveawayType::OnlyNewMembers), + }; } + state->confirmButtonBusy = true; + Payments::CheckoutProcess::Start( + std::move(invoice), + crl::guard(box, [=](auto) { + state->confirmButtonBusy = false; + box->window()->setFocus(); + })); }); box->addButton(std::move(button)); }