| 834 | } |
| 835 | |
| 836 | std::optional<Data::StarGift> FromTL( |
| 837 | not_null<Main::Session*> session, |
| 838 | const MTPstarGift &gift) { |
| 839 | return gift.match([&](const MTPDstarGift &data) { |
| 840 | const auto document = session->data().processDocument( |
| 841 | data.vsticker()); |
| 842 | const auto resellPrice = data.vresell_min_stars().value_or_empty(); |
| 843 | const auto remaining = data.vavailability_remains(); |
| 844 | const auto total = data.vavailability_total(); |
| 845 | if (!document->sticker()) { |
| 846 | return std::optional<Data::StarGift>(); |
| 847 | } |
| 848 | const auto releasedById = data.vreleased_by() |
| 849 | ? peerFromMTP(*data.vreleased_by()) |
| 850 | : PeerId(); |
| 851 | const auto releasedBy = releasedById |
| 852 | ? session->data().peer(releasedById).get() |
| 853 | : nullptr; |
| 854 | const auto background = [&] { |
| 855 | if (!data.vbackground()) { |
| 856 | return std::shared_ptr<Data::StarGiftBackground>(); |
| 857 | } |
| 858 | const auto &fields = data.vbackground()->data(); |
| 859 | using namespace Ui; |
| 860 | return std::make_shared<Data::StarGiftBackground>( |
| 861 | Data::StarGiftBackground{ |
| 862 | .center = ColorFromSerialized(fields.vcenter_color()), |
| 863 | .edge = ColorFromSerialized(fields.vedge_color()), |
| 864 | .text = ColorFromSerialized(fields.vtext_color()), |
| 865 | }); |
| 866 | }; |
| 867 | return std::optional<Data::StarGift>(Data::StarGift{ |
| 868 | .id = uint64(data.vid().v), |
| 869 | .background = background(), |
| 870 | .stars = int64(data.vstars().v), |
| 871 | .starsConverted = int64(data.vconvert_stars().v), |
| 872 | .starsToUpgrade = int64(data.vupgrade_stars().value_or_empty()), |
| 873 | .starsResellMin = int64(resellPrice), |
| 874 | .document = document, |
| 875 | .releasedBy = releasedBy, |
| 876 | .resellTitle = qs(data.vtitle().value_or_empty()), |
| 877 | .resellCount = int(data.vavailability_resale().value_or_empty()), |
| 878 | .auctionSlug = qs(data.vauction_slug().value_or_empty()), |
| 879 | .auctionGiftsPerRound = data.vgifts_per_round().value_or_empty(), |
| 880 | .auctionStartDate = data.vauction_start_date().value_or_empty(), |
| 881 | .limitedLeft = remaining.value_or_empty(), |
| 882 | .limitedCount = total.value_or_empty(), |
| 883 | .perUserTotal = data.vper_user_total().value_or_empty(), |
| 884 | .perUserRemains = data.vper_user_remains().value_or_empty(), |
| 885 | .upgradeVariants = data.vupgrade_variants().value_or_empty(), |
| 886 | .firstSaleDate = data.vfirst_sale_date().value_or_empty(), |
| 887 | .lastSaleDate = data.vlast_sale_date().value_or_empty(), |
| 888 | .lockedUntilDate = data.vlocked_until_date().value_or_empty(), |
| 889 | .requirePremium = data.is_require_premium(), |
| 890 | .peerColorAvailable = data.is_peer_color_available(), |
| 891 | .upgradable = data.vupgrade_stars().has_value(), |
| 892 | .birthday = data.is_birthday(), |
| 893 | .soldOut = data.is_sold_out(), |
no test coverage detected