| 828 | } |
| 829 | |
| 830 | void 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( |
nothing calls this directly
no test coverage detected