mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-07-26 23:43:06 +02:00
Added support of statistics availability to Credits component.
This commit is contained in:
parent
3667ef551c
commit
759258bb39
2 changed files with 26 additions and 9 deletions
|
@ -47,10 +47,23 @@ void Credits::load(bool force) {
|
|||
&& _lastLoaded + kReloadThreshold > crl::now())) {
|
||||
return;
|
||||
}
|
||||
_loader = std::make_unique<Api::CreditsStatus>(_session->user());
|
||||
_loader->request({}, [=](Data::CreditsStatusSlice slice) {
|
||||
const auto self = _session->user();
|
||||
_loader = std::make_unique<rpl::lifetime>();
|
||||
_loader->make_state<Api::CreditsStatus>(self)->request({}, [=](
|
||||
Data::CreditsStatusSlice slice) {
|
||||
const auto balance = slice.balance;
|
||||
const auto apiStats
|
||||
= _loader->make_state<Api::CreditsEarnStatistics>(self);
|
||||
const auto finish = [=](bool statsEnabled) {
|
||||
_statsEnabled = statsEnabled;
|
||||
apply(balance);
|
||||
_loader = nullptr;
|
||||
apply(slice.balance);
|
||||
};
|
||||
apiStats->request() | rpl::start_with_error_done([=] {
|
||||
finish(false);
|
||||
}, [=] {
|
||||
finish(true);
|
||||
}, *_loader);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -148,4 +161,8 @@ rpl::producer<> Credits::refreshedByPeerId(PeerId peerId) {
|
|||
) | rpl::filter(rpl::mappers::_1 == peerId) | rpl::to_empty;
|
||||
}
|
||||
|
||||
bool Credits::statsEnabled() const {
|
||||
return _statsEnabled;
|
||||
}
|
||||
|
||||
} // namespace Data
|
||||
|
|
|
@ -7,10 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
namespace Api {
|
||||
class CreditsStatus;
|
||||
} // namespace Api
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
@ -39,6 +35,8 @@ public:
|
|||
|
||||
[[nodiscard]] rpl::producer<> refreshedByPeerId(PeerId peerId);
|
||||
|
||||
[[nodiscard]] bool statsEnabled() const;
|
||||
|
||||
void applyCurrency(PeerId peerId, uint64 balance);
|
||||
[[nodiscard]] uint64 balanceCurrency(PeerId peerId) const;
|
||||
|
||||
|
@ -54,7 +52,7 @@ private:
|
|||
|
||||
const not_null<Main::Session*> _session;
|
||||
|
||||
std::unique_ptr<Api::CreditsStatus> _loader;
|
||||
std::unique_ptr<rpl::lifetime> _loader;
|
||||
|
||||
base::flat_map<PeerId, StarsAmount> _cachedPeerBalances;
|
||||
base::flat_map<PeerId, uint64> _cachedPeerCurrencyBalances;
|
||||
|
@ -66,6 +64,8 @@ private:
|
|||
crl::time _lastLoaded = 0;
|
||||
float64 _rate = 0.;
|
||||
|
||||
bool _statsEnabled = false;
|
||||
|
||||
rpl::event_stream<PeerId> _refreshedByPeerId;
|
||||
|
||||
SingleQueuedInvokation _reload;
|
||||
|
|
Loading…
Add table
Reference in a new issue