mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Added API support for prepaid giveaways.
This commit is contained in:
parent
43aa8825a5
commit
3522d9c62e
6 changed files with 95 additions and 35 deletions
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -50,10 +50,18 @@ struct BoostsListSlice final {
|
|||
OffsetToken token;
|
||||
};
|
||||
|
||||
struct BoostPrepaidGiveaway final {
|
||||
int months = 0;
|
||||
uint64 id = 0;
|
||||
int quantity = 0;
|
||||
QDateTime date;
|
||||
};
|
||||
|
||||
struct BoostStatus final {
|
||||
BoostsOverview overview;
|
||||
BoostsListSlice firstSliceBoosts;
|
||||
BoostsListSlice firstSliceGifts;
|
||||
std::vector<BoostPrepaidGiveaway> prepaidGiveaway;
|
||||
QString link;
|
||||
};
|
||||
|
||||
|
|
|
@ -130,6 +130,39 @@ not_null<Main::Session*> SessionFromId(const InvoiceId &id) {
|
|||
return &giveaway.boostPeer->session();
|
||||
}
|
||||
|
||||
MTPinputStorePaymentPurpose InvoicePremiumGiftCodeGiveawayToTL(
|
||||
const InvoicePremiumGiftCode &invoice) {
|
||||
const auto &giveaway = v::get<InvoicePremiumGiftCodeGiveaway>(
|
||||
invoice.purpose);
|
||||
using Flag = MTPDinputStorePaymentPremiumGiveaway::Flag;
|
||||
return MTP_inputStorePaymentPremiumGiveaway(
|
||||
MTP_flags(Flag()
|
||||
| (giveaway.onlyNewSubscribers
|
||||
? Flag::f_only_new_subscribers
|
||||
: Flag())
|
||||
| (giveaway.additionalChannels.empty()
|
||||
? Flag()
|
||||
: Flag::f_additional_peers)
|
||||
| (giveaway.countries.empty()
|
||||
? Flag()
|
||||
: Flag::f_countries_iso2)),
|
||||
giveaway.boostPeer->input,
|
||||
MTP_vector_from_range(ranges::views::all(
|
||||
giveaway.additionalChannels
|
||||
) | ranges::views::transform([](not_null<ChannelData*> c) {
|
||||
return MTPInputPeer(c->input);
|
||||
})),
|
||||
MTP_vector_from_range(ranges::views::all(
|
||||
giveaway.countries
|
||||
) | ranges::views::transform([](QString value) {
|
||||
return MTP_string(value);
|
||||
})),
|
||||
MTP_long(invoice.randomId),
|
||||
MTP_int(giveaway.untilDate),
|
||||
MTP_string(invoice.currency),
|
||||
MTP_long(invoice.amount));
|
||||
}
|
||||
|
||||
Form::Form(InvoiceId id, bool receipt)
|
||||
: _id(id)
|
||||
, _session(SessionFromId(id))
|
||||
|
@ -305,36 +338,8 @@ MTPInputInvoice Form::inputInvoice() const {
|
|||
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.countries.empty()
|
||||
? Flag()
|
||||
: Flag::f_countries_iso2)),
|
||||
giveaway.boostPeer->input,
|
||||
MTP_vector_from_range(ranges::views::all(
|
||||
giveaway.additionalChannels
|
||||
) | ranges::views::transform([](not_null<ChannelData*> c) {
|
||||
return MTPInputPeer(c->input);
|
||||
})),
|
||||
MTP_vector_from_range(ranges::views::all(
|
||||
giveaway.countries
|
||||
) | ranges::views::transform([](QString value) {
|
||||
return MTP_string(value);
|
||||
})),
|
||||
MTP_long(giftCode.randomId),
|
||||
MTP_int(giveaway.untilDate),
|
||||
MTP_string(giftCode.currency),
|
||||
MTP_long(giftCode.amount)),
|
||||
InvoicePremiumGiftCodeGiveawayToTL(giftCode),
|
||||
option);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -219,6 +219,9 @@ struct InvoiceId {
|
|||
|
||||
[[nodiscard]] not_null<Main::Session*> SessionFromId(const InvoiceId &id);
|
||||
|
||||
[[nodiscard]] MTPinputStorePaymentPurpose InvoicePremiumGiftCodeGiveawayToTL(
|
||||
const InvoicePremiumGiftCode &invoice);
|
||||
|
||||
class Form final : public base::has_weak_ptr {
|
||||
public:
|
||||
Form(InvoiceId id, bool receipt);
|
||||
|
|
Loading…
Add table
Reference in a new issue