Added list of giftcode options to giveaway box.

This commit is contained in:
23rd 2023-10-30 14:41:57 +03:00 committed by John Preston
parent e67d2e5db2
commit aa6edea33a
3 changed files with 59 additions and 1 deletions

View file

@ -7,16 +7,21 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "info/boosts/create_giveaway_box.h"
#include "api/api_premium.h"
#include "boxes/peers/edit_participants_box.h" // ParticipantsBoxController
#include "data/data_peer.h"
#include "data/data_subscription_option.h"
#include "data/data_user.h"
#include "info/boosts/giveaway/giveaway_type_row.h"
#include "info/info_controller.h"
#include "lang/lang_keys.h"
#include "settings/settings_common.h"
#include "ui/effects/premium_graphics.h"
#include "ui/layers/generic_box.h"
#include "ui/widgets/checkbox.h"
#include "ui/widgets/labels.h"
#include "styles/style_layers.h"
#include "styles/style_premium.h"
namespace {
@ -59,10 +64,16 @@ void CreateGiveawayBox(
not_null<Info::Controller*> controller,
not_null<PeerData*> peer) {
struct State final {
State(not_null<PeerData*> p) : apiOptions(p) {
}
Api::PremiumGiftCodeOptions apiOptions;
rpl::lifetime lifetimeApi;
std::vector<not_null<PeerData*>> selectedToAward;
rpl::event_stream<> toAwardAmountChanged;
};
const auto state = box->lifetime().make_state<State>();
const auto state = box->lifetime().make_state<State>(peer);
using GiveawayType = Giveaway::GiveawayTypeRow::Type;
using GiveawayGroup = Ui::RadioenumGroup<GiveawayType>;
const auto typeGroup = std::make_shared<GiveawayGroup>();
@ -129,6 +140,48 @@ void CreateGiveawayBox(
}
typeGroup->setValue(GiveawayType::Random);
Settings::AddSkip(box->verticalLayout());
Settings::AddDivider(box->verticalLayout());
Settings::AddSkip(box->verticalLayout());
{
const auto listOptions = box->verticalLayout()->add(
object_ptr<Ui::VerticalLayout>(box));
const auto durationGroup = std::make_shared<Ui::RadiobuttonGroup>(0);
const auto rebuildListOptions = [=](int amountUsers) {
while (listOptions->count()) {
delete listOptions->widgetAt(0);
}
Ui::Premium::AddGiftOptions(
listOptions,
durationGroup,
state->apiOptions.options(amountUsers),
st::giveawayGiftCodeGiftOption,
true);
listOptions->resizeToWidth(box->width());
};
typeGroup->setChangedCallback([=](GiveawayType type) {
const auto rebuild = [=] {
rebuildListOptions((type == GiveawayType::SpecificUsers)
? state->selectedToAward.size()
: 1);
};
if (!listOptions->count()) {
state->lifetimeApi = state->apiOptions.request(
) | rpl::start_with_error_done([=](const QString &error) {
}, rebuild);
} else {
rebuild();
}
});
state->lifetimeApi = state->apiOptions.request(
) | rpl::start_with_error_done([=](const QString &error) {
}, [=] {
rebuildListOptions(1);
});
}
box->addButton(tr::lng_box_ok(), [=] {
box->closeBox();
});

View file

@ -288,6 +288,10 @@ giveawayGiftCodeLinkHeight: 42px;
giveawayGiftCodeLinkCopyWidth: 40px;
giveawayGiftCodeLinkMargin: margins(24px, 8px, 24px, 12px);
giveawayGiftCodeGiftOption: PremiumOption(premiumGiftOption) {
badgeShift: point(5px, 0px);
}
boostLinkStatsButton: IconButton(defaultIconButton) {
width: giveawayGiftCodeLinkCopyWidth;
height: giveawayGiftCodeLinkHeight;

View file

@ -1320,6 +1320,7 @@ void AddGiftOptions(
stCheckbox,
std::move(radioView));
radio->setAttribute(Qt::WA_TransparentForMouseEvents);
radio->show();
{ // Paint the last frame instantly for the layer animation.
group->setValue(0);
radio->finishAnimating();