Show correct error on gift limit reaching.

This commit is contained in:
John Preston
2025-09-01 17:14:55 +04:00
parent c0c5ad21b6
commit 9df98352a8
4 changed files with 22 additions and 0 deletions
@@ -2041,6 +2041,7 @@ void SendGift(
.message = details.text,
.recipient = peer,
.limitedCount = gift.info.limitedCount,
.perUserLimit = gift.info.perUserTotal,
.anonymous = details.anonymous,
.upgraded = details.upgraded,
}, done, processNonPanelPaymentFormFactory);
@@ -2952,6 +2953,16 @@ void SendGiftBox(
[=] { state->resaleRequestingId = 0; });
} else if (star && IsSoldOut(star->info)) {
window->show(Box(SoldOutBox, window, *star));
} else if (star
&& star->info.perUserTotal
&& !star->info.perUserRemains) {
window->showToast({
.text = tr::lng_gift_sent_finished(
tr::now,
lt_count,
star->info.perUserTotal,
Ui::Text::RichLangValue),
});
} else {
send();
}
@@ -533,6 +533,7 @@ void Form::requestForm() {
.invoice = invoice,
.inputInvoice = inputInvoice(),
.starGiftLimitedCount = gift ? gift->limitedCount : 0,
.starGiftPerUserLimit = gift ? gift->perUserLimit : 0,
.starGiftForm = true,
};
_updates.fire(CreditsPaymentStarted{ .data = formData });
@@ -179,6 +179,7 @@ struct InvoiceStarGift {
TextWithEntities message;
not_null<PeerData*> recipient;
int limitedCount = 0;
int perUserLimit = 0;
bool anonymous = false;
bool upgraded = false;
};
@@ -202,6 +203,7 @@ struct CreditsFormData {
InvoiceCredits invoice;
MTPInputInvoice inputInvoice;
int starGiftLimitedCount = 0;
int starGiftPerUserLimit = 0;
bool starGiftForm = false;
};
@@ -77,6 +77,14 @@ void ProcessCreditsPayment(
show->showToast(
tr::lng_gift_sold_out_title(tr::now));
}
} else if (*error == u"STARGIFT_USER_USAGE_LIMITED"_q) {
show->showToast({
.text = tr::lng_gift_sent_finished(
tr::now,
lt_count,
std::max(form->starGiftPerUserLimit, 1),
Ui::Text::RichLangValue),
});
} else {
show->showToast(*error);
}