mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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 {
|
const std::vector<int> &PremiumGiftCodeOptions::availablePresets() const {
|
||||||
return _availablePresets;
|
return _availablePresets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] int PremiumGiftCodeOptions::monthsFromPreset(int monthsIndex) {
|
||||||
|
return _optionsForOnePerson.months[monthsIndex];
|
||||||
|
}
|
||||||
|
|
||||||
Payments::InvoicePremiumGiftCode PremiumGiftCodeOptions::invoice(
|
Payments::InvoicePremiumGiftCode PremiumGiftCodeOptions::invoice(
|
||||||
int users,
|
int users,
|
||||||
int monthsIndex) {
|
int months) {
|
||||||
const auto randomId = base::RandomValue<uint64>();
|
const auto randomId = base::RandomValue<uint64>();
|
||||||
const auto token = Token{
|
const auto token = Token{ users, months };
|
||||||
users,
|
|
||||||
_optionsForOnePerson.months[monthsIndex],
|
|
||||||
};
|
|
||||||
const auto &store = _stores[token];
|
const auto &store = _stores[token];
|
||||||
return Payments::InvoicePremiumGiftCode{
|
return Payments::InvoicePremiumGiftCode{
|
||||||
.randomId = randomId,
|
.randomId = randomId,
|
||||||
|
|
|
@ -152,9 +152,13 @@ public:
|
||||||
[[nodiscard]] rpl::producer<rpl::no_value, QString> request();
|
[[nodiscard]] rpl::producer<rpl::no_value, QString> request();
|
||||||
[[nodiscard]] Data::SubscriptionOptions options(int amount);
|
[[nodiscard]] Data::SubscriptionOptions options(int amount);
|
||||||
[[nodiscard]] const std::vector<int> &availablePresets() const;
|
[[nodiscard]] const std::vector<int> &availablePresets() const;
|
||||||
|
[[nodiscard]] int monthsFromPreset(int monthsIndex);
|
||||||
[[nodiscard]] Payments::InvoicePremiumGiftCode invoice(
|
[[nodiscard]] Payments::InvoicePremiumGiftCode invoice(
|
||||||
int users,
|
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 giveawayBoostsPerPremium() const;
|
||||||
[[nodiscard]] int giveawayCountriesMax() const;
|
[[nodiscard]] int giveawayCountriesMax() const;
|
||||||
|
|
|
@ -533,6 +533,20 @@ rpl::producer<rpl::no_value, QString> Boosts::request() {
|
||||||
};
|
};
|
||||||
_boostStatus.link = qs(data.vboost_url());
|
_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;
|
using namespace Data;
|
||||||
requestBoosts({ .gifts = false }, [=](BoostsListSlice &&slice) {
|
requestBoosts({ .gifts = false }, [=](BoostsListSlice &&slice) {
|
||||||
_boostStatus.firstSliceBoosts = std::move(slice);
|
_boostStatus.firstSliceBoosts = std::move(slice);
|
||||||
|
|
|
@ -50,10 +50,18 @@ struct BoostsListSlice final {
|
||||||
OffsetToken token;
|
OffsetToken token;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct BoostPrepaidGiveaway final {
|
||||||
|
int months = 0;
|
||||||
|
uint64 id = 0;
|
||||||
|
int quantity = 0;
|
||||||
|
QDateTime date;
|
||||||
|
};
|
||||||
|
|
||||||
struct BoostStatus final {
|
struct BoostStatus final {
|
||||||
BoostsOverview overview;
|
BoostsOverview overview;
|
||||||
BoostsListSlice firstSliceBoosts;
|
BoostsListSlice firstSliceBoosts;
|
||||||
BoostsListSlice firstSliceGifts;
|
BoostsListSlice firstSliceGifts;
|
||||||
|
std::vector<BoostPrepaidGiveaway> prepaidGiveaway;
|
||||||
QString link;
|
QString link;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -130,6 +130,39 @@ not_null<Main::Session*> SessionFromId(const InvoiceId &id) {
|
||||||
return &giveaway.boostPeer->session();
|
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)
|
Form::Form(InvoiceId id, bool receipt)
|
||||||
: _id(id)
|
: _id(id)
|
||||||
, _session(SessionFromId(id))
|
, _session(SessionFromId(id))
|
||||||
|
@ -305,36 +338,8 @@ MTPInputInvoice Form::inputInvoice() const {
|
||||||
MTP_long(giftCode.amount)),
|
MTP_long(giftCode.amount)),
|
||||||
option);
|
option);
|
||||||
} else {
|
} else {
|
||||||
const auto &giveaway = v::get<InvoicePremiumGiftCodeGiveaway>(
|
|
||||||
giftCode.purpose);
|
|
||||||
using Flag = MTPDinputStorePaymentPremiumGiveaway::Flag;
|
|
||||||
return MTP_inputInvoicePremiumGiftCode(
|
return MTP_inputInvoicePremiumGiftCode(
|
||||||
MTP_inputStorePaymentPremiumGiveaway(
|
InvoicePremiumGiftCodeGiveawayToTL(giftCode),
|
||||||
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)),
|
|
||||||
option);
|
option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,6 +219,9 @@ struct InvoiceId {
|
||||||
|
|
||||||
[[nodiscard]] not_null<Main::Session*> SessionFromId(const InvoiceId &id);
|
[[nodiscard]] not_null<Main::Session*> SessionFromId(const InvoiceId &id);
|
||||||
|
|
||||||
|
[[nodiscard]] MTPinputStorePaymentPurpose InvoicePremiumGiftCodeGiveawayToTL(
|
||||||
|
const InvoicePremiumGiftCode &invoice);
|
||||||
|
|
||||||
class Form final : public base::has_weak_ptr {
|
class Form final : public base::has_weak_ptr {
|
||||||
public:
|
public:
|
||||||
Form(InvoiceId id, bool receipt);
|
Form(InvoiceId id, bool receipt);
|
||||||
|
|
Loading…
Add table
Reference in a new issue