Check gift sold out error on sending.

This commit is contained in:
John Preston 2024-10-11 09:47:41 +04:00
parent db475ef0b4
commit 1a0fd35f36
4 changed files with 25 additions and 1 deletions

View file

@ -842,6 +842,7 @@ void SendGift(
.randomId = details.randomId,
.message = details.text,
.user = peer->asUser(),
.limitedCount = gift.limitedCount,
.anonymous = details.anonymous,
}, done, processNonPanelPaymentFormFactory);
});

View file

@ -501,11 +501,13 @@ void Form::requestForm() {
.currency = currency,
.amount = amount,
};
const auto gift = std::get_if<InvoiceStarGift>(&_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 });

View file

@ -177,6 +177,7 @@ struct InvoiceStarGift {
uint64 randomId = 0;
TextWithEntities message;
not_null<UserData*> 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;
};

View file

@ -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<QString> 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);
}