MCPcopy Create free account
hub / github.com/TDesktop-x64/tdesktop / GiftCodeBox

Function GiftCodeBox

Telegram/SourceFiles/boxes/gift_premium_box.cpp:830–957  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

828}
829
830void GiftCodeBox(
831 not_null<Ui::GenericBox*> box,
832 not_null<Window::SessionNavigation*> controller,
833 const QString &slug) {
834 struct State {
835 rpl::variable<Api::GiftCode> data;
836 rpl::variable<bool> used;
837 bool sent = false;
838 };
839 const auto session = &controller->session();
840 const auto state = box->lifetime().make_state<State>(State{});
841 state->data = session->api().premium().giftCodeValue(slug);
842 state->used = state->data.value(
843 ) | rpl::map([=](const Api::GiftCode &data) {
844 return data.used != 0;
845 });
846
847 box->setWidth(st::boxWideWidth);
848 box->setStyle(st::giveawayGiftCodeBox);
849 box->setNoContentMargin(true);
850
851 const auto bar = box->setPinnedToTopContent(
852 object_ptr<Ui::Premium::TopBar>(
853 box,
854 st::giveawayGiftCodeCover,
855 Ui::Premium::TopBarDescriptor{
856 .clickContextOther = nullptr,
857 .title = rpl::conditional(
858 state->used.value(),
859 tr::lng_gift_link_used_title(),
860 tr::lng_gift_link_title()),
861 .about = rpl::conditional(
862 state->used.value(),
863 tr::lng_gift_link_used_about(tr::rich),
864 tr::lng_gift_link_about(tr::rich)),
865 .light = true,
866 }));
867
868 const auto max = st::giveawayGiftCodeTopHeight;
869 bar->setMaximumHeight(max);
870 bar->setMinimumHeight(st::infoLayerTopBarHeight);
871
872 bar->resize(bar->width(), bar->maximumHeight());
873
874 const auto link = MakeGiftCodeLink(&controller->session(), slug);
875 box->addRow(
876 Ui::MakeLinkLabel(
877 box,
878 rpl::single(link.text),
879 rpl::single(link.link),
880 box->uiShow(),
881 MakeLinkCopyIcon(box)),
882 st::giveawayGiftCodeLinkMargin);
883
884 const auto show = controller->uiShow();
885 AddTable(box->verticalLayout(), show, {}, state->data.current(), false);
886
887 auto shareLink = tr::lng_gift_link_also_send_link(

Callers

nothing calls this directly

Calls 15

MakeGiftCodeLinkFunction · 0.85
MakeLinkCopyIconFunction · 0.85
AddTableFunction · 0.85
langDateTimeFunction · 0.85
ShareWithFriendFunction · 0.85
StartFireworksFunction · 0.85
ShowAlreadyPremiumToastFunction · 0.85
giftCodeValueMethod · 0.80
apiMethod · 0.80
resizeMethod · 0.80
applyGiftCodeMethod · 0.80
MakeLinkLabelFunction · 0.50

Tested by

no test coverage detected