mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Update API scheme to layer 195.
This commit is contained in:
@@ -19,6 +19,11 @@ constexpr auto kReloadThreshold = 60 * crl::time(1000);
|
||||
|
||||
} // namespace
|
||||
|
||||
StarsAmount FromTL(const MTPStarsAmount &value) {
|
||||
const auto &data = value.data();
|
||||
return StarsAmount(data.vamount().v, data.vnanos().v);
|
||||
}
|
||||
|
||||
Credits::Credits(not_null<Main::Session*> session)
|
||||
: _session(session)
|
||||
, _reload([=] { load(true); }) {
|
||||
@@ -27,7 +32,7 @@ Credits::Credits(not_null<Main::Session*> session)
|
||||
Credits::~Credits() = default;
|
||||
|
||||
void Credits::apply(const MTPDupdateStarsBalance &data) {
|
||||
apply(data.vbalance().v);
|
||||
apply(FromTL(data.vbalance()));
|
||||
}
|
||||
|
||||
rpl::producer<float64> Credits::rateValue(
|
||||
@@ -65,13 +70,13 @@ rpl::producer<bool> Credits::loadedValue() const {
|
||||
) | rpl::then(_loadedChanges.events() | rpl::map_to(true));
|
||||
}
|
||||
|
||||
uint64 Credits::balance() const {
|
||||
StarsAmount Credits::balance() const {
|
||||
return _nonLockedBalance.current();
|
||||
}
|
||||
|
||||
uint64 Credits::balance(PeerId peerId) const {
|
||||
StarsAmount Credits::balance(PeerId peerId) const {
|
||||
const auto it = _cachedPeerBalances.find(peerId);
|
||||
return (it != _cachedPeerBalances.end()) ? it->second : 0;
|
||||
return (it != _cachedPeerBalances.end()) ? it->second : StarsAmount();
|
||||
}
|
||||
|
||||
uint64 Credits::balanceCurrency(PeerId peerId) const {
|
||||
@@ -79,17 +84,19 @@ uint64 Credits::balanceCurrency(PeerId peerId) const {
|
||||
return (it != _cachedPeerCurrencyBalances.end()) ? it->second : 0;
|
||||
}
|
||||
|
||||
rpl::producer<uint64> Credits::balanceValue() const {
|
||||
rpl::producer<StarsAmount> Credits::balanceValue() const {
|
||||
return _nonLockedBalance.value();
|
||||
}
|
||||
|
||||
void Credits::updateNonLockedValue() {
|
||||
_nonLockedBalance = (_balance >= _locked) ? (_balance - _locked) : 0;
|
||||
_nonLockedBalance = (_balance >= _locked)
|
||||
? (_balance - _locked)
|
||||
: StarsAmount();
|
||||
}
|
||||
|
||||
void Credits::lock(int count) {
|
||||
void Credits::lock(StarsAmount count) {
|
||||
Expects(loaded());
|
||||
Expects(count >= 0);
|
||||
Expects(count >= StarsAmount(0));
|
||||
Expects(_locked + count <= _balance);
|
||||
|
||||
_locked += count;
|
||||
@@ -97,8 +104,8 @@ void Credits::lock(int count) {
|
||||
updateNonLockedValue();
|
||||
}
|
||||
|
||||
void Credits::unlock(int count) {
|
||||
Expects(count >= 0);
|
||||
void Credits::unlock(StarsAmount count) {
|
||||
Expects(count >= StarsAmount(0));
|
||||
Expects(_locked >= count);
|
||||
|
||||
_locked -= count;
|
||||
@@ -106,12 +113,12 @@ void Credits::unlock(int count) {
|
||||
updateNonLockedValue();
|
||||
}
|
||||
|
||||
void Credits::withdrawLocked(int count) {
|
||||
Expects(count >= 0);
|
||||
void Credits::withdrawLocked(StarsAmount count) {
|
||||
Expects(count >= StarsAmount(0));
|
||||
Expects(_locked >= count);
|
||||
|
||||
_locked -= count;
|
||||
apply(_balance >= count ? (_balance - count) : 0);
|
||||
apply(_balance >= count ? (_balance - count) : StarsAmount(0));
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@@ -119,7 +126,7 @@ void Credits::invalidate() {
|
||||
_reload.call();
|
||||
}
|
||||
|
||||
void Credits::apply(uint64 balance) {
|
||||
void Credits::apply(StarsAmount balance) {
|
||||
_balance = balance;
|
||||
updateNonLockedValue();
|
||||
|
||||
@@ -129,7 +136,7 @@ void Credits::apply(uint64 balance) {
|
||||
}
|
||||
}
|
||||
|
||||
void Credits::apply(PeerId peerId, uint64 balance) {
|
||||
void Credits::apply(PeerId peerId, StarsAmount balance) {
|
||||
_cachedPeerBalances[peerId] = balance;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user