diff --git a/Telegram/SourceFiles/boxes/star_gift_box.cpp b/Telegram/SourceFiles/boxes/star_gift_box.cpp index 38262bce38..580db09cd3 100644 --- a/Telegram/SourceFiles/boxes/star_gift_box.cpp +++ b/Telegram/SourceFiles/boxes/star_gift_box.cpp @@ -842,6 +842,7 @@ void SendGift( .randomId = details.randomId, .message = details.text, .user = peer->asUser(), + .limitedCount = gift.limitedCount, .anonymous = details.anonymous, }, done, processNonPanelPaymentFormFactory); }); diff --git a/Telegram/SourceFiles/payments/payments_form.cpp b/Telegram/SourceFiles/payments/payments_form.cpp index 56d107b7d9..7941404c46 100644 --- a/Telegram/SourceFiles/payments/payments_form.cpp +++ b/Telegram/SourceFiles/payments/payments_form.cpp @@ -501,11 +501,13 @@ void Form::requestForm() { .currency = currency, .amount = amount, }; + const auto gift = std::get_if(&_id.value); const auto formData = CreditsFormData{ .id = _id, .formId = data.vform_id().v, .invoice = invoice, .inputInvoice = inputInvoice(), + .starGiftLimitedCount = gift ? gift->limitedCount : 0, .starGiftForm = true, }; _updates.fire(CreditsPaymentStarted{ .data = formData }); diff --git a/Telegram/SourceFiles/payments/payments_form.h b/Telegram/SourceFiles/payments/payments_form.h index 0a364a9b16..9b0d38d4d5 100644 --- a/Telegram/SourceFiles/payments/payments_form.h +++ b/Telegram/SourceFiles/payments/payments_form.h @@ -177,6 +177,7 @@ struct InvoiceStarGift { uint64 randomId = 0; TextWithEntities message; not_null user; + int limitedCount = 0; bool anonymous = false; }; @@ -198,6 +199,7 @@ struct CreditsFormData { PhotoData *photo = nullptr; InvoiceCredits invoice; MTPInputInvoice inputInvoice; + int starGiftLimitedCount = 0; bool starGiftForm = false; }; diff --git a/Telegram/SourceFiles/payments/payments_non_panel_process.cpp b/Telegram/SourceFiles/payments/payments_non_panel_process.cpp index 9f3652b1a0..6f348df4f3 100644 --- a/Telegram/SourceFiles/payments/payments_non_panel_process.cpp +++ b/Telegram/SourceFiles/payments/payments_non_panel_process.cpp @@ -25,6 +25,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/boxes/boost_box.h" // Ui::StartFireworks. #include "ui/layers/generic_box.h" #include "ui/text/format_values.h" +#include "ui/text/text_utilities.h" +#include "ui/toast/toast.h" #include "window/window_controller.h" #include "window/window_session_controller.h" @@ -59,7 +61,24 @@ void ProcessCreditsPayment( const auto done = [=](std::optional error) { const auto onstack = maybeReturnToBot; if (error) { - show->showToast(*error); + if (*error == u"STARGIFT_USAGE_LIMITED"_q) { + if (form->starGiftLimitedCount) { + show->showToast({ + .title = tr::lng_gift_sold_out_title( + tr::now), + .text = tr::lng_gift_sold_out_text( + tr::now, + lt_count_decimal, + form->starGiftLimitedCount, + Ui::Text::RichLangValue), + }); + } else { + show->showToast( + tr::lng_gift_sold_out_title(tr::now)); + } + } else { + show->showToast(*error); + } if (onstack) { onstack(CheckoutResult::Failed); }