2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Added API support for prepaid giveaways.

This commit is contained in:
23rd
2023-11-08 14:54:45 +03:00
parent 43aa8825a5
commit 3522d9c62e
6 changed files with 95 additions and 35 deletions

View File

@@ -390,18 +390,44 @@ rpl::producer<rpl::no_value, QString> PremiumGiftCodeOptions::request() {
};
}
rpl::producer<rpl::no_value, QString> PremiumGiftCodeOptions::applyPrepaid(
const Payments::InvoicePremiumGiftCode &invoice,
uint64 prepaidId) {
return [=](auto consumer) {
auto lifetime = rpl::lifetime();
const auto channel = _peer->asChannel();
if (!channel) {
return lifetime;
}
_api.request(MTPpayments_LaunchPrepaidGiveaway(
_peer->input,
MTP_long(prepaidId),
Payments::InvoicePremiumGiftCodeGiveawayToTL(invoice)
)).done([=](const MTPUpdates &result) {
_peer->session().api().applyUpdates(result);
consumer.put_done();
}).fail([=](const MTP::Error &error) {
consumer.put_error_copy(error.type());
}).send();
return lifetime;
};
}
const std::vector<int> &PremiumGiftCodeOptions::availablePresets() const {
return _availablePresets;
}
[[nodiscard]] int PremiumGiftCodeOptions::monthsFromPreset(int monthsIndex) {
return _optionsForOnePerson.months[monthsIndex];
}
Payments::InvoicePremiumGiftCode PremiumGiftCodeOptions::invoice(
int users,
int monthsIndex) {
int months) {
const auto randomId = base::RandomValue<uint64>();
const auto token = Token{
users,
_optionsForOnePerson.months[monthsIndex],
};
const auto token = Token{ users, months };
const auto &store = _stores[token];
return Payments::InvoicePremiumGiftCode{
.randomId = randomId,

View File

@@ -152,9 +152,13 @@ public:
[[nodiscard]] rpl::producer<rpl::no_value, QString> request();
[[nodiscard]] Data::SubscriptionOptions options(int amount);
[[nodiscard]] const std::vector<int> &availablePresets() const;
[[nodiscard]] int monthsFromPreset(int monthsIndex);
[[nodiscard]] Payments::InvoicePremiumGiftCode invoice(
int users,
int monthsIndex);
int months);
[[nodiscard]] rpl::producer<rpl::no_value, QString> applyPrepaid(
const Payments::InvoicePremiumGiftCode &invoice,
uint64 prepaidId);
[[nodiscard]] int giveawayBoostsPerPremium() const;
[[nodiscard]] int giveawayCountriesMax() const;

View File

@@ -533,6 +533,20 @@ rpl::producer<rpl::no_value, QString> Boosts::request() {
};
_boostStatus.link = qs(data.vboost_url());
if (data.vprepaid_giveaways()) {
_boostStatus.prepaidGiveaway = ranges::views::all(
data.vprepaid_giveaways()->v
) | ranges::views::transform([](const MTPPrepaidGiveaway &r) {
return Data::BoostPrepaidGiveaway{
.months = r.data().vmonths().v,
.id = r.data().vid().v,
.quantity = r.data().vquantity().v,
.date = QDateTime::fromSecsSinceEpoch(
r.data().vdate().v),
};
}) | ranges::to_vector;
}
using namespace Data;
requestBoosts({ .gifts = false }, [=](BoostsListSlice &&slice) {
_boostStatus.firstSliceBoosts = std::move(slice);