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

View file

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