2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Support correct paid-media-from-bot phrases.

This commit is contained in:
John Preston
2024-08-13 14:35:12 +02:00
parent 9ea495f59d
commit a2785867b2
5 changed files with 59 additions and 30 deletions

View File

@@ -81,43 +81,42 @@ rpl::producer<bool> Credits::loadedValue() const {
}
uint64 Credits::balance() const {
const auto balance = _balance.current();
const auto locked = _locked.current();
return (balance >= locked) ? (balance - locked) : 0;
return _nonLockedBalance.current();
}
rpl::producer<uint64> Credits::balanceValue() const {
return rpl::combine(
_balance.value(),
_locked.value()
) | rpl::map([=](uint64 balance, uint64 locked) {
return (balance >= locked) ? (balance - locked) : 0;
});
return _nonLockedBalance.value();
}
void Credits::updateNonLockedValue() {
_nonLockedBalance = (_balance >= _locked) ? (_balance - _locked) : 0;
}
void Credits::lock(int count) {
Expects(loaded());
Expects(count >= 0);
Expects(_locked + count <= _balance);
_locked = _locked.current() + count;
_locked += count;
Ensures(_locked.current() <= _balance.current());
updateNonLockedValue();
}
void Credits::unlock(int count) {
Expects(count >= 0);
Expects(_locked.current() >= count);
Expects(_locked >= count);
_locked = _locked.current() - count;
_locked -= count;
updateNonLockedValue();
}
void Credits::withdrawLocked(int count) {
Expects(count >= 0);
Expects(_locked.current() >= count);
Expects(_locked >= count);
const auto balance = _balance.current();
_locked = _locked.current() - count;
apply(balance >= count ? (balance - count) : 0);
_locked -= count;
apply(_balance >= count ? (_balance - count) : 0);
invalidate();
}
@@ -127,6 +126,7 @@ void Credits::invalidate() {
void Credits::apply(uint64 balance) {
_balance = balance;
updateNonLockedValue();
const auto was = std::exchange(_lastLoaded, crl::now());
if (!was) {