Added api support of subscription details.

This commit is contained in:
23rd 2024-11-13 01:23:54 +03:00 committed by John Preston
parent 479e369d29
commit 17e54104a9
2 changed files with 16 additions and 2 deletions

View file

@ -133,17 +133,26 @@ constexpr auto kTransactionsLimit = 100;
}
[[nodiscard]] Data::SubscriptionEntry SubscriptionFromTL(
const MTPStarsSubscription &tl) {
const MTPStarsSubscription &tl,
not_null<PeerData*> peer) {
return Data::SubscriptionEntry{
.id = qs(tl.data().vid()),
.inviteHash = qs(tl.data().vchat_invite_hash().value_or_empty()),
.title = qs(tl.data().vtitle().value_or_empty()),
.slug = qs(tl.data().vinvoice_slug().value_or_empty()),
.until = base::unixtime::parse(tl.data().vuntil_date().v),
.subscription = Data::PeerSubscription{
.credits = tl.data().vpricing().data().vamount().v,
.period = tl.data().vpricing().data().vperiod().v,
},
.barePeerId = peerFromMTP(tl.data().vpeer()).value,
.photoId = (tl.data().vphoto()
? peer->owner().photoFromWeb(
*tl.data().vphoto(),
ImageLocation())->id
: 0),
.cancelled = tl.data().is_canceled(),
.cancelledByBot = tl.data().is_bot_canceled(),
.expired = (base::unixtime::now() > tl.data().vuntil_date().v),
.canRefulfill = tl.data().is_can_refulfill(),
};
@ -166,7 +175,7 @@ constexpr auto kTransactionsLimit = 100;
if (const auto history = data.vsubscriptions()) {
subscriptions.reserve(history->v.size());
for (const auto &tl : history->v) {
subscriptions.push_back(SubscriptionFromTL(tl));
subscriptions.push_back(SubscriptionFromTL(tl, peer));
}
}
return Data::CreditsStatusSlice{

View file

@ -18,6 +18,7 @@ struct PeerSubscription final {
}
};
using PhotoId = uint64;
struct SubscriptionEntry final {
explicit operator bool() const {
return !id.isEmpty();
@ -25,10 +26,14 @@ struct SubscriptionEntry final {
QString id;
QString inviteHash;
QString title;
QString slug;
QDateTime until;
PeerSubscription subscription;
uint64 barePeerId = 0;
PhotoId photoId = PhotoId(0);
bool cancelled = false;
bool cancelledByBot = false;
bool expired = false;
bool canRefulfill = false;
};