From 5e28b2d6012af28740a6fcf67ffeddca2a98636a Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 1 Nov 2023 00:46:58 +0300 Subject: [PATCH] Added ability to select channels to giveaway box. --- .../info/boosts/create_giveaway_box.cpp | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp b/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp index 626a01b789..52f5c7283c 100644 --- a/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp +++ b/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp @@ -65,6 +65,8 @@ void CreateGiveawayBox( std::vector> selectedToAward; rpl::event_stream<> toAwardAmountChanged; + std::vector> selectedToSubscribe; + rpl::variable typeValue; rpl::variable sliderValue; rpl::variable dateValue; @@ -232,6 +234,75 @@ void CreateGiveawayBox( sliderContainer->resizeToWidth(box->width()); }; + { + const auto channelsContainer = randomWrap->entity()->add( + object_ptr(randomWrap)); + Settings::AddSubsectionTitle( + channelsContainer, + tr::lng_giveaway_channels_title()); + + struct ListState final { + ListState(not_null p) : controller(p) { + } + PeerListContentDelegateSimple delegate; + Giveaway::SelectedChannelsListController controller; + }; + const auto listState = box->lifetime().make_state(peer); + + listState->delegate.setContent(channelsContainer->add( + object_ptr( + channelsContainer, + &listState->controller))); + listState->controller.setDelegate(&listState->delegate); + listState->controller.channelRemoved( + ) | rpl::start_with_next([=](not_null peer) { + auto &list = state->selectedToSubscribe; + list.erase(ranges::remove(list, peer), end(list)); + }, box->lifetime()); + listState->controller.setTopStatus(tr::lng_giveaway_channels_this( + lt_count, + state->sliderValue.value( + ) | rpl::map([=](int v) -> float64 { + return state->apiOptions.giveawayBoostsPerPremium() * v; + }))); + + using IconType = Settings::IconType; + Settings::AddButton( + channelsContainer, + tr::lng_giveaway_channels_add(), + st::settingsButtonActive, + { &st::settingsIconAdd, IconType::Round, &st::windowBgActive } + )->setClickedCallback([=] { + auto initBox = [=](not_null peersBox) { + peersBox->setTitle(tr::lng_giveaway_channels_add()); + peersBox->addButton(tr::lng_settings_save(), [=] { + const auto selected = peersBox->collectSelectedRows(); + state->selectedToSubscribe = selected; + listState->controller.rebuild(selected); + peersBox->closeBox(); + }); + peersBox->addButton(tr::lng_cancel(), [=] { + peersBox->closeBox(); + }); + }; + + box->uiShow()->showBox( + Box( + std::make_unique( + peer, + box->uiShow(), + state->selectedToSubscribe), + std::move(initBox)), + Ui::LayerOption::KeepOther); + }); + + Settings::AddSkip(channelsContainer); + Settings::AddDividerText( + channelsContainer, + tr::lng_giveaway_channels_about()); + Settings::AddSkip(channelsContainer); + } + { const auto dateContainer = randomWrap->entity()->add( object_ptr(randomWrap));