mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 22:54:01 +02:00
Added api support for subscriptions list.
This commit is contained in:
parent
cc3baad377
commit
ec93a91db2
4 changed files with 81 additions and 7 deletions
|
@ -111,25 +111,53 @@ constexpr auto kTransactionsLimit = 100;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] Data::SubscriptionEntry SubscriptionFromTL(
|
||||||
|
const MTPStarsSubscription &tl) {
|
||||||
|
return Data::SubscriptionEntry{
|
||||||
|
.id = qs(tl.data().vid()),
|
||||||
|
.inviteHash = qs(tl.data().vchat_invite_hash().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,
|
||||||
|
.cancelled = tl.data().is_canceled(),
|
||||||
|
.expired = (base::unixtime::now() > tl.data().vuntil_date().v),
|
||||||
|
.canRefulfill = tl.data().is_can_refulfill(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] Data::CreditsStatusSlice StatusFromTL(
|
[[nodiscard]] Data::CreditsStatusSlice StatusFromTL(
|
||||||
const MTPpayments_StarsStatus &status,
|
const MTPpayments_StarsStatus &status,
|
||||||
not_null<PeerData*> peer) {
|
not_null<PeerData*> peer) {
|
||||||
const auto &data = status.data();
|
const auto &data = status.data();
|
||||||
peer->owner().processUsers(data.vusers());
|
peer->owner().processUsers(data.vusers());
|
||||||
peer->owner().processChats(data.vchats());
|
peer->owner().processChats(data.vchats());
|
||||||
auto list = std::vector<Data::CreditsHistoryEntry>();
|
auto entries = std::vector<Data::CreditsHistoryEntry>();
|
||||||
if (const auto history = data.vhistory()) {
|
if (const auto history = data.vhistory()) {
|
||||||
list = ranges::views::all(
|
entries.reserve(history->v.size());
|
||||||
history->v
|
for (const auto &tl : history->v) {
|
||||||
) | ranges::views::transform([&](const MTPStarsTransaction &tl) {
|
entries.push_back(HistoryFromTL(tl, peer));
|
||||||
return HistoryFromTL(tl, peer);
|
}
|
||||||
}) | ranges::to_vector;
|
}
|
||||||
|
auto subscriptions = std::vector<Data::SubscriptionEntry>();
|
||||||
|
if (const auto history = data.vsubscriptions()) {
|
||||||
|
subscriptions.reserve(history->v.size());
|
||||||
|
for (const auto &tl : history->v) {
|
||||||
|
subscriptions.push_back(SubscriptionFromTL(tl));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Data::CreditsStatusSlice{
|
return Data::CreditsStatusSlice{
|
||||||
.list = std::move(list),
|
.list = std::move(entries),
|
||||||
|
.subscriptions = std::move(subscriptions),
|
||||||
.balance = status.data().vbalance().v,
|
.balance = status.data().vbalance().v,
|
||||||
|
.subscriptionsMissingBalance
|
||||||
|
= status.data().vsubscriptions_missing_balance().value_or_empty(),
|
||||||
.allLoaded = !status.data().vnext_offset().has_value(),
|
.allLoaded = !status.data().vnext_offset().has_value(),
|
||||||
.token = qs(status.data().vnext_offset().value_or_empty()),
|
.token = qs(status.data().vnext_offset().value_or_empty()),
|
||||||
|
.tokenSubscriptions = qs(
|
||||||
|
status.data().vsubscriptions_next_offset().value_or_empty()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,6 +275,25 @@ void CreditsHistory::request(
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CreditsHistory::requestSubscriptions(
|
||||||
|
const Data::CreditsStatusSlice::OffsetToken &token,
|
||||||
|
Fn<void(Data::CreditsStatusSlice)> done) {
|
||||||
|
if (_requestId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_requestId = _api.request(MTPpayments_GetStarsSubscriptions(
|
||||||
|
MTP_flags(0),
|
||||||
|
_peer->isSelf() ? MTP_inputPeerSelf() : _peer->input,
|
||||||
|
MTP_string(token)
|
||||||
|
)).done([=](const MTPpayments_StarsStatus &result) {
|
||||||
|
_requestId = 0;
|
||||||
|
done(StatusFromTL(result, _peer));
|
||||||
|
}).fail([=] {
|
||||||
|
_requestId = 0;
|
||||||
|
done({});
|
||||||
|
}).send();
|
||||||
|
}
|
||||||
|
|
||||||
Data::CreditTopupOptions CreditsTopupOptions::options() const {
|
Data::CreditTopupOptions CreditsTopupOptions::options() const {
|
||||||
return _options;
|
return _options;
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,9 @@ public:
|
||||||
void request(
|
void request(
|
||||||
const Data::CreditsStatusSlice::OffsetToken &token,
|
const Data::CreditsStatusSlice::OffsetToken &token,
|
||||||
Fn<void(Data::CreditsStatusSlice)> done);
|
Fn<void(Data::CreditsStatusSlice)> done);
|
||||||
|
void requestSubscriptions(
|
||||||
|
const Data::CreditsStatusSlice::OffsetToken &token,
|
||||||
|
Fn<void(Data::CreditsStatusSlice)> done);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using HistoryTL = MTPpayments_GetStarsTransactions;
|
using HistoryTL = MTPpayments_GetStarsTransactions;
|
||||||
|
|
|
@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "data/data_subscriptions.h"
|
||||||
|
|
||||||
namespace Data {
|
namespace Data {
|
||||||
|
|
||||||
struct CreditTopupOption final {
|
struct CreditTopupOption final {
|
||||||
|
@ -31,6 +33,10 @@ struct CreditsHistoryMedia {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CreditsHistoryEntry final {
|
struct CreditsHistoryEntry final {
|
||||||
|
explicit operator bool() const {
|
||||||
|
return !id.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
using PhotoId = uint64;
|
using PhotoId = uint64;
|
||||||
enum class PeerType {
|
enum class PeerType {
|
||||||
Peer,
|
Peer,
|
||||||
|
@ -66,9 +72,12 @@ struct CreditsHistoryEntry final {
|
||||||
struct CreditsStatusSlice final {
|
struct CreditsStatusSlice final {
|
||||||
using OffsetToken = QString;
|
using OffsetToken = QString;
|
||||||
std::vector<CreditsHistoryEntry> list;
|
std::vector<CreditsHistoryEntry> list;
|
||||||
|
std::vector<SubscriptionEntry> subscriptions;
|
||||||
uint64 balance = 0;
|
uint64 balance = 0;
|
||||||
|
uint64 subscriptionsMissingBalance = 0;
|
||||||
bool allLoaded = false;
|
bool allLoaded = false;
|
||||||
OffsetToken token;
|
OffsetToken token;
|
||||||
|
OffsetToken tokenSubscriptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Data
|
} // namespace Data
|
||||||
|
|
|
@ -18,4 +18,19 @@ struct PeerSubscription final {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SubscriptionEntry final {
|
||||||
|
explicit operator bool() const {
|
||||||
|
return !id.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString id;
|
||||||
|
QString inviteHash;
|
||||||
|
QDateTime until;
|
||||||
|
PeerSubscription subscription;
|
||||||
|
uint64 barePeerId = 0;
|
||||||
|
bool cancelled = false;
|
||||||
|
bool expired = false;
|
||||||
|
bool canRefulfill = false;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace Data
|
} // namespace Data
|
||||||
|
|
Loading…
Add table
Reference in a new issue