diff options
author | John Preston <johnprestonmail@gmail.com> | 2023-10-06 11:15:26 +0400 |
---|---|---|
committer | John Preston <johnprestonmail@gmail.com> | 2023-10-26 14:08:40 +0400 |
commit | b08869abdb63a2148e05258b4222e1824cc67e0d (patch) | |
tree | 5b6dd5c05e2829e8e14b01eafbcb5a63acf5b42d /Telegram/SourceFiles/payments/payments_form.cpp | |
parent | d5147c9d286a320b39329750dc59418f7a490d15 (diff) |
Support giveaway message layout.
Diffstat (limited to 'Telegram/SourceFiles/payments/payments_form.cpp')
-rw-r--r-- | Telegram/SourceFiles/payments/payments_form.cpp | 87 |
1 files changed, 76 insertions, 11 deletions
diff --git a/Telegram/SourceFiles/payments/payments_form.cpp b/Telegram/SourceFiles/payments/payments_form.cpp index 62682b9dbe..37bb927a8f 100644 --- a/Telegram/SourceFiles/payments/payments_form.cpp +++ b/Telegram/SourceFiles/payments/payments_form.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "payments/payments_form.h" #include "main/main_session.h" +#include "data/data_channel.h" #include "data/data_session.h" #include "data/data_media_types.h" #include "data/data_user.h" @@ -112,10 +113,21 @@ constexpr auto kPasswordPeriod = 15 * TimeId(60); } // namespace not_null<Main::Session*> SessionFromId(const InvoiceId &id) { - if (const auto slug = std::get_if<InvoiceSlug>(&id.value)) { + if (const auto message = std::get_if<InvoiceMessage>(&id.value)) { + return &message->peer->session(); + } else if (const auto slug = std::get_if<InvoiceSlug>(&id.value)) { return slug->session; } - return &v::get<InvoiceMessage>(id.value).peer->session(); + const auto &giftCode = v::get<InvoicePremiumGiftCode>(id.value); + const auto users = std::get_if<InvoicePremiumGiftCodeUsers>( + &giftCode.purpose); + if (users) { + Assert(!users->users.empty()); + return &users->users.front()->session(); + } + const auto &giveaway = v::get<InvoicePremiumGiftCodeGiveaway>( + giftCode.purpose); + return &giveaway.boostPeer->session(); } Form::Form(InvoiceId id, bool receipt) @@ -207,11 +219,10 @@ void Form::loadThumbnail(not_null<PhotoData*> photo) { } Data::FileOrigin Form::thumbnailFileOrigin() const { - if (const auto slug = std::get_if<InvoiceSlug>(&_id.value)) { - return Data::FileOrigin(); + if (const auto message = std::get_if<InvoiceMessage>(&_id.value)) { + return FullMsgId(message->peer->id, message->itemId); } - const auto message = v::get<InvoiceMessage>(_id.value); - return FullMsgId(message.peer->id, message.itemId); + return Data::FileOrigin(); } QImage Form::prepareGoodThumbnail( @@ -257,13 +268,67 @@ QImage Form::prepareEmptyThumbnail() const { } MTPInputInvoice Form::inputInvoice() const { - if (const auto slug = std::get_if<InvoiceSlug>(&_id.value)) { + if (const auto message = std::get_if<InvoiceMessage>(&_id.value)) { + return MTP_inputInvoiceMessage( + message->peer->input, + MTP_int(message->itemId.bare)); + } else if (const auto slug = std::get_if<InvoiceSlug>(&_id.value)) { return MTP_inputInvoiceSlug(MTP_string(slug->slug)); } - const auto message = v::get<InvoiceMessage>(_id.value); - return MTP_inputInvoiceMessage( - message.peer->input, - MTP_int(message.itemId.bare)); + const auto &giftCode = v::get<InvoicePremiumGiftCode>(_id.value); + using Flag = MTPDpremiumGiftCodeOption::Flag; + const auto option = MTP_premiumGiftCodeOption( + MTP_flags((giftCode.storeQuantity ? Flag::f_store_quantity : Flag()) + | (giftCode.storeProduct.isEmpty() + ? Flag() + : Flag::f_store_product)), + MTP_int(giftCode.users), + MTP_int(giftCode.months), + MTP_string(giftCode.storeProduct), + MTP_int(giftCode.storeQuantity), + MTP_string(giftCode.currency), + MTP_long(giftCode.amount)); + const auto users = std::get_if<InvoicePremiumGiftCodeUsers>( + &giftCode.purpose); + if (users) { + using Flag = MTPDinputStorePaymentPremiumGiftCode::Flag; + return MTP_inputInvoicePremiumGiftCode( + MTP_inputStorePaymentPremiumGiftCode( + MTP_flags(users->boostPeer ? Flag::f_boost_peer : Flag()), + MTP_vector<MTPInputUser>(ranges::views::all( + users->users + ) | ranges::views::transform([](not_null<UserData*> user) { + return MTPInputUser(user->inputUser); + }) | ranges::to<QVector>), + users->boostPeer ? users->boostPeer->input : MTPInputPeer(), + MTP_string(giftCode.currency), + MTP_long(giftCode.amount)), + option); + } else { + const auto &giveaway = v::get<InvoicePremiumGiftCodeGiveaway>( + giftCode.purpose); + using Flag = MTPDinputStorePaymentPremiumGiveaway::Flag; + return MTP_inputInvoicePremiumGiftCode( + MTP_inputStorePaymentPremiumGiveaway( + MTP_flags(Flag() + | (giveaway.onlyNewSubscribers + ? Flag::f_only_new_subscribers + : Flag()) + | (giveaway.additionalChannels.empty() + ? Flag() + : Flag::f_additional_peers)), + giveaway.boostPeer->input, + MTP_vector<MTPInputPeer>(ranges::views::all( + giveaway.additionalChannels + ) | ranges::views::transform([](not_null<ChannelData*> c) { + return MTPInputPeer(c->input); + }) | ranges::to<QVector>()), + MTP_long(giftCode.randomId), + MTP_int(giveaway.untilDate), + MTP_string(giftCode.currency), + MTP_long(giftCode.amount)), + option); + } } void Form::requestForm() { |