mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added initial api support for credits giveaway options.
This commit is contained in:
parent
f445440995
commit
7e5e6003a9
2 changed files with 74 additions and 4 deletions
|
@ -215,6 +215,10 @@ rpl::producer<rpl::no_value, QString> CreditsTopupOptions::request() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Data::CreditTopupOptions CreditsTopupOptions::options() const {
|
||||||
|
return _options;
|
||||||
|
}
|
||||||
|
|
||||||
CreditsStatus::CreditsStatus(not_null<PeerData*> peer)
|
CreditsStatus::CreditsStatus(not_null<PeerData*> peer)
|
||||||
: _peer(peer)
|
: _peer(peer)
|
||||||
, _api(&peer->session().api().instance()) {
|
, _api(&peer->session().api().instance()) {
|
||||||
|
@ -294,10 +298,6 @@ void CreditsHistory::requestSubscriptions(
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
Data::CreditTopupOptions CreditsTopupOptions::options() const {
|
|
||||||
return _options;
|
|
||||||
}
|
|
||||||
|
|
||||||
rpl::producer<not_null<PeerData*>> PremiumPeerBot(
|
rpl::producer<not_null<PeerData*>> PremiumPeerBot(
|
||||||
not_null<Main::Session*> session) {
|
not_null<Main::Session*> session) {
|
||||||
const auto username = session->appConfig().get<QString>(
|
const auto username = session->appConfig().get<QString>(
|
||||||
|
@ -385,4 +385,58 @@ Data::CreditsEarnStatistics CreditsEarnStatistics::data() const {
|
||||||
return _data;
|
return _data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CreditsGiveawayOptions::CreditsGiveawayOptions(not_null<PeerData*> peer)
|
||||||
|
: _peer(peer)
|
||||||
|
, _api(&peer->session().api().instance()) {
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<rpl::no_value, QString> CreditsGiveawayOptions::request() {
|
||||||
|
return [=](auto consumer) {
|
||||||
|
auto lifetime = rpl::lifetime();
|
||||||
|
|
||||||
|
using TLOption = MTPStarsGiveawayOption;
|
||||||
|
|
||||||
|
const auto optionsFromTL = [=](const auto &options) {
|
||||||
|
return ranges::views::all(
|
||||||
|
options
|
||||||
|
) | ranges::views::transform([=](const auto &option) {
|
||||||
|
return Data::CreditsGiveawayOption{
|
||||||
|
.winners = ranges::views::all(
|
||||||
|
option.data().vwinners().v
|
||||||
|
) | ranges::views::transform([](const auto &winner) {
|
||||||
|
return Data::CreditsGiveawayOption::Winner{
|
||||||
|
.users = winner.data().vusers().v,
|
||||||
|
.perUserStars = winner.data().vper_user_stars().v,
|
||||||
|
.isDefault = winner.data().is_default(),
|
||||||
|
};
|
||||||
|
}) | ranges::to_vector,
|
||||||
|
.storeProduct = qs(
|
||||||
|
option.data().vstore_product().value_or_empty()),
|
||||||
|
.currency = qs(option.data().vcurrency()),
|
||||||
|
.amount = option.data().vamount().v,
|
||||||
|
.credits = option.data().vstars().v,
|
||||||
|
.yearlyBoosts = option.data().vyearly_boosts().v,
|
||||||
|
.isExtended = option.data().is_extended(),
|
||||||
|
.isDefault = option.data().is_default(),
|
||||||
|
};
|
||||||
|
}) | ranges::to_vector;
|
||||||
|
};
|
||||||
|
const auto fail = [=](const MTP::Error &error) {
|
||||||
|
consumer.put_error_copy(error.type());
|
||||||
|
};
|
||||||
|
|
||||||
|
_api.request(MTPpayments_GetStarsGiveawayOptions(
|
||||||
|
)).done([=](const MTPVector<TLOption> &result) {
|
||||||
|
_options = optionsFromTL(result.v);
|
||||||
|
consumer.put_done();
|
||||||
|
}).fail(fail).send();
|
||||||
|
|
||||||
|
return lifetime;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Data::CreditsGiveawayOptions CreditsGiveawayOptions::options() const {
|
||||||
|
return _options;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Api
|
} // namespace Api
|
||||||
|
|
|
@ -36,6 +36,22 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CreditsGiveawayOptions final {
|
||||||
|
public:
|
||||||
|
CreditsGiveawayOptions(not_null<PeerData*> peer);
|
||||||
|
|
||||||
|
[[nodiscard]] rpl::producer<rpl::no_value, QString> request();
|
||||||
|
[[nodiscard]] Data::CreditsGiveawayOptions options() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const not_null<PeerData*> _peer;
|
||||||
|
|
||||||
|
Data::CreditsGiveawayOptions _options;
|
||||||
|
|
||||||
|
MTP::Sender _api;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
class CreditsStatus final {
|
class CreditsStatus final {
|
||||||
public:
|
public:
|
||||||
CreditsStatus(not_null<PeerData*> peer);
|
CreditsStatus(not_null<PeerData*> peer);
|
||||||
|
|
Loading…
Add table
Reference in a new issue