mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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());
|
_session->data().stories().apply(data.vstealth_mode());
|
||||||
} break;
|
} 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();
|
return _premiumPossible.current();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpl::producer<uint64> Session::creditsValue() const {
|
||||||
|
return _credits.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Session::setCredits(uint64 credits) {
|
||||||
|
_credits = credits;
|
||||||
|
}
|
||||||
|
|
||||||
bool Session::isTestMode() const {
|
bool Session::isTestMode() const {
|
||||||
return mtp().isTestMode();
|
return mtp().isTestMode();
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,9 @@ public:
|
||||||
[[nodiscard]] bool premiumBadgesShown() const;
|
[[nodiscard]] bool premiumBadgesShown() const;
|
||||||
[[nodiscard]] bool premiumCanBuy() const;
|
[[nodiscard]] bool premiumCanBuy() const;
|
||||||
|
|
||||||
|
[[nodiscard]] rpl::producer<uint64> creditsValue() const;
|
||||||
|
void setCredits(uint64 credits);
|
||||||
|
|
||||||
[[nodiscard]] bool isTestMode() const;
|
[[nodiscard]] bool isTestMode() const;
|
||||||
[[nodiscard]] uint64 uniqueId() const; // userId() with TestDC shift.
|
[[nodiscard]] uint64 uniqueId() const; // userId() with TestDC shift.
|
||||||
[[nodiscard]] UserId userId() const;
|
[[nodiscard]] UserId userId() const;
|
||||||
|
@ -258,6 +261,7 @@ private:
|
||||||
const std::unique_ptr<Support::Helper> _supportHelper;
|
const std::unique_ptr<Support::Helper> _supportHelper;
|
||||||
|
|
||||||
std::shared_ptr<QImage> _selfUserpicView;
|
std::shared_ptr<QImage> _selfUserpicView;
|
||||||
|
rpl::variable<uint64> _credits = 0;
|
||||||
rpl::variable<bool> _premiumPossible = false;
|
rpl::variable<bool> _premiumPossible = false;
|
||||||
|
|
||||||
rpl::event_stream<bool> _termsLockChanges;
|
rpl::event_stream<bool> _termsLockChanges;
|
||||||
|
|
|
@ -578,12 +578,16 @@ QPointer<Ui::RpWidget> Credits::createPinnedToTop(
|
||||||
+ diffBetweenStarAndCount),
|
+ diffBetweenStarAndCount),
|
||||||
label->style()->font->height + starSize.height());
|
label->style()->font->height + starSize.height());
|
||||||
};
|
};
|
||||||
api->request({}, [=](Data::CreditsStatusSlice slice) {
|
_controller->session().creditsValue(
|
||||||
|
) | rpl::start_with_next([=](uint64 value) {
|
||||||
count->setText(
|
count->setText(
|
||||||
st::semiboldTextStyle,
|
st::semiboldTextStyle,
|
||||||
Lang::FormatCountToShort(slice.balance).string);
|
Lang::FormatCountToShort(value).string);
|
||||||
balance->setBalance(slice.balance);
|
balance->setBalance(value);
|
||||||
resize();
|
resize();
|
||||||
|
}, balance->lifetime());
|
||||||
|
api->request({}, [=](Data::CreditsStatusSlice slice) {
|
||||||
|
_controller->session().setCredits(slice.balance);
|
||||||
});
|
});
|
||||||
balance->paintRequest(
|
balance->paintRequest(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "settings/settings_main.h"
|
#include "settings/settings_main.h"
|
||||||
|
|
||||||
|
#include "api/api_credits.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "core/click_handler_types.h"
|
#include "core/click_handler_types.h"
|
||||||
#include "settings/settings_advanced.h"
|
#include "settings/settings_advanced.h"
|
||||||
|
@ -491,9 +492,13 @@ void SetupPremium(
|
||||||
showOther(PremiumId());
|
showOther(PremiumId());
|
||||||
});
|
});
|
||||||
AddPremiumStar(
|
AddPremiumStar(
|
||||||
AddButtonWithIcon(
|
AddButtonWithLabel(
|
||||||
container,
|
container,
|
||||||
tr::lng_credits_summary_title(),
|
tr::lng_credits_summary_title(),
|
||||||
|
controller->session().creditsValue(
|
||||||
|
) | rpl::map([=](uint64 c) {
|
||||||
|
return c ? Lang::FormatCountToShort(c).string : QString{};
|
||||||
|
}),
|
||||||
st::settingsButton),
|
st::settingsButton),
|
||||||
true
|
true
|
||||||
)->addClickHandler([=] {
|
)->addClickHandler([=] {
|
||||||
|
@ -510,6 +515,12 @@ void SetupPremium(
|
||||||
});
|
});
|
||||||
Ui::NewBadge::AddToRight(button);
|
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()) {
|
if (controller->session().premiumCanBuy()) {
|
||||||
const auto button = AddButtonWithIcon(
|
const auto button = AddButtonWithIcon(
|
||||||
container,
|
container,
|
||||||
|
|
Loading…
Add table
Reference in a new issue