mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Added credits balance to main session.
This commit is contained in:
parent
174fb62c32
commit
e11755af46
5 changed files with 36 additions and 4 deletions
|
@ -2614,6 +2614,11 @@ void Updates::feedUpdate(const MTPUpdate &update) {
|
|||
_session->data().stories().apply(data.vstealth_mode());
|
||||
} break;
|
||||
|
||||
case mtpc_updateStarsBalance: {
|
||||
const auto &data = update.c_updateStarsBalance();
|
||||
_session->setCredits(data.vbalance().v);
|
||||
} break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -280,6 +280,14 @@ bool Session::premiumCanBuy() const {
|
|||
return _premiumPossible.current();
|
||||
}
|
||||
|
||||
rpl::producer<uint64> Session::creditsValue() const {
|
||||
return _credits.value();
|
||||
}
|
||||
|
||||
void Session::setCredits(uint64 credits) {
|
||||
_credits = credits;
|
||||
}
|
||||
|
||||
bool Session::isTestMode() const {
|
||||
return mtp().isTestMode();
|
||||
}
|
||||
|
|
|
@ -100,6 +100,9 @@ public:
|
|||
[[nodiscard]] bool premiumBadgesShown() const;
|
||||
[[nodiscard]] bool premiumCanBuy() const;
|
||||
|
||||
[[nodiscard]] rpl::producer<uint64> creditsValue() const;
|
||||
void setCredits(uint64 credits);
|
||||
|
||||
[[nodiscard]] bool isTestMode() const;
|
||||
[[nodiscard]] uint64 uniqueId() const; // userId() with TestDC shift.
|
||||
[[nodiscard]] UserId userId() const;
|
||||
|
@ -258,6 +261,7 @@ private:
|
|||
const std::unique_ptr<Support::Helper> _supportHelper;
|
||||
|
||||
std::shared_ptr<QImage> _selfUserpicView;
|
||||
rpl::variable<uint64> _credits = 0;
|
||||
rpl::variable<bool> _premiumPossible = false;
|
||||
|
||||
rpl::event_stream<bool> _termsLockChanges;
|
||||
|
|
|
@ -578,12 +578,16 @@ QPointer<Ui::RpWidget> Credits::createPinnedToTop(
|
|||
+ diffBetweenStarAndCount),
|
||||
label->style()->font->height + starSize.height());
|
||||
};
|
||||
api->request({}, [=](Data::CreditsStatusSlice slice) {
|
||||
_controller->session().creditsValue(
|
||||
) | rpl::start_with_next([=](uint64 value) {
|
||||
count->setText(
|
||||
st::semiboldTextStyle,
|
||||
Lang::FormatCountToShort(slice.balance).string);
|
||||
balance->setBalance(slice.balance);
|
||||
Lang::FormatCountToShort(value).string);
|
||||
balance->setBalance(value);
|
||||
resize();
|
||||
}, balance->lifetime());
|
||||
api->request({}, [=](Data::CreditsStatusSlice slice) {
|
||||
_controller->session().setCredits(slice.balance);
|
||||
});
|
||||
balance->paintRequest(
|
||||
) | rpl::start_with_next([=] {
|
||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "settings/settings_main.h"
|
||||
|
||||
#include "api/api_credits.h"
|
||||
#include "core/application.h"
|
||||
#include "core/click_handler_types.h"
|
||||
#include "settings/settings_advanced.h"
|
||||
|
@ -491,9 +492,13 @@ void SetupPremium(
|
|||
showOther(PremiumId());
|
||||
});
|
||||
AddPremiumStar(
|
||||
AddButtonWithIcon(
|
||||
AddButtonWithLabel(
|
||||
container,
|
||||
tr::lng_credits_summary_title(),
|
||||
controller->session().creditsValue(
|
||||
) | rpl::map([=](uint64 c) {
|
||||
return c ? Lang::FormatCountToShort(c).string : QString{};
|
||||
}),
|
||||
st::settingsButton),
|
||||
true
|
||||
)->addClickHandler([=] {
|
||||
|
@ -510,6 +515,12 @@ void SetupPremium(
|
|||
});
|
||||
Ui::NewBadge::AddToRight(button);
|
||||
|
||||
const auto api = button->lifetime().make_state<Api::CreditsStatus>(
|
||||
controller->session().user());
|
||||
api->request({}, [=](Data::CreditsStatusSlice slice) {
|
||||
controller->session().setCredits(slice.balance);
|
||||
});
|
||||
|
||||
if (controller->session().premiumCanBuy()) {
|
||||
const auto button = AddButtonWithIcon(
|
||||
container,
|
||||
|
|
Loading…
Add table
Reference in a new issue