mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 15:43:55 +02:00
Made more rpl-friendly balance label in channel profile.
This commit is contained in:
parent
53cee177e8
commit
6bd0bf6e69
4 changed files with 56 additions and 20 deletions
|
@ -135,10 +135,17 @@ void Credits::apply(StarsAmount balance) {
|
||||||
|
|
||||||
void Credits::apply(PeerId peerId, StarsAmount balance) {
|
void Credits::apply(PeerId peerId, StarsAmount balance) {
|
||||||
_cachedPeerBalances[peerId] = balance;
|
_cachedPeerBalances[peerId] = balance;
|
||||||
|
_refreshedByPeerId.fire_copy(peerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Credits::applyCurrency(PeerId peerId, uint64 balance) {
|
void Credits::applyCurrency(PeerId peerId, uint64 balance) {
|
||||||
_cachedPeerCurrencyBalances[peerId] = balance;
|
_cachedPeerCurrencyBalances[peerId] = balance;
|
||||||
|
_refreshedByPeerId.fire_copy(peerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<> Credits::refreshedByPeerId(PeerId peerId) {
|
||||||
|
return _refreshedByPeerId.events(
|
||||||
|
) | rpl::filter(rpl::mappers::_1 == peerId) | rpl::to_empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Data
|
} // namespace Data
|
||||||
|
|
|
@ -37,6 +37,8 @@ public:
|
||||||
[[nodiscard]] rpl::producer<float64> rateValue(
|
[[nodiscard]] rpl::producer<float64> rateValue(
|
||||||
not_null<PeerData*> ownedBotOrChannel);
|
not_null<PeerData*> ownedBotOrChannel);
|
||||||
|
|
||||||
|
[[nodiscard]] rpl::producer<> refreshedByPeerId(PeerId peerId);
|
||||||
|
|
||||||
void applyCurrency(PeerId peerId, uint64 balance);
|
void applyCurrency(PeerId peerId, uint64 balance);
|
||||||
[[nodiscard]] uint64 balanceCurrency(PeerId peerId) const;
|
[[nodiscard]] uint64 balanceCurrency(PeerId peerId) const;
|
||||||
|
|
||||||
|
@ -64,6 +66,8 @@ private:
|
||||||
crl::time _lastLoaded = 0;
|
crl::time _lastLoaded = 0;
|
||||||
float64 _rate = 0.;
|
float64 _rate = 0.;
|
||||||
|
|
||||||
|
rpl::event_stream<PeerId> _refreshedByPeerId;
|
||||||
|
|
||||||
SingleQueuedInvokation _reload;
|
SingleQueuedInvokation _reload;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1360,7 +1360,8 @@ void ApplyChannelUpdate(
|
||||||
channel->setWallPaper({});
|
channel->setWallPaper({});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channel->flags() & Flag::CanViewRevenue) {
|
if ((channel->flags() & Flag::CanViewRevenue)
|
||||||
|
|| (channel->flags() & Flag::CanViewCreditsRevenue)) {
|
||||||
static constexpr auto kTimeout = crl::time(60000);
|
static constexpr auto kTimeout = crl::time(60000);
|
||||||
const auto id = channel->id;
|
const auto id = channel->id;
|
||||||
const auto weak = base::make_weak(&channel->session());
|
const auto weak = base::make_weak(&channel->session());
|
||||||
|
|
|
@ -2833,13 +2833,34 @@ object_ptr<Ui::RpWidget> SetupChannelMembersAndManage(
|
||||||
st::menuIconAdmin,
|
st::menuIconAdmin,
|
||||||
st::infoChannelAdminsIconPosition);
|
st::infoChannelAdminsIconPosition);
|
||||||
|
|
||||||
if (channel->session().credits().balanceCurrency(channel->id) > 0
|
const auto canViewBalance = false
|
||||||
|| channel->session().credits().balance(channel->id)) {
|
|| (channel->flags() & ChannelDataFlag::CanViewRevenue)
|
||||||
|
|| (channel->flags() & ChannelDataFlag::CanViewCreditsRevenue)
|
||||||
|
|| (channel->loadedStatus() != ChannelData::LoadedStatus::Full);
|
||||||
|
if (canViewBalance) {
|
||||||
const auto balanceWrap = result->entity()->add(
|
const auto balanceWrap = result->entity()->add(
|
||||||
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||||
result->entity(),
|
result->entity(),
|
||||||
object_ptr<Ui::VerticalLayout>(result->entity())));
|
object_ptr<Ui::VerticalLayout>(result->entity())));
|
||||||
balanceWrap->toggle(true, anim::type::instant);
|
auto refreshed = channel->session().credits().refreshedByPeerId(
|
||||||
|
channel->id);
|
||||||
|
auto creditsValue = rpl::single(
|
||||||
|
rpl::empty_value()
|
||||||
|
) | rpl::then(rpl::duplicate(refreshed)) | rpl::map([=] {
|
||||||
|
return channel->session().credits().balance(channel->id).whole();
|
||||||
|
});
|
||||||
|
auto currencyValue = rpl::single(
|
||||||
|
rpl::empty_value()
|
||||||
|
) | rpl::then(rpl::duplicate(refreshed)) | rpl::map([=] {
|
||||||
|
return channel->session().credits().balanceCurrency(channel->id);
|
||||||
|
});
|
||||||
|
balanceWrap->toggleOn(
|
||||||
|
rpl::combine(
|
||||||
|
rpl::duplicate(creditsValue),
|
||||||
|
rpl::duplicate(currencyValue)
|
||||||
|
) | rpl::map(rpl::mappers::_1 > 0 || rpl::mappers::_2 > 0),
|
||||||
|
anim::type::normal);
|
||||||
|
balanceWrap->finishAnimating();
|
||||||
|
|
||||||
const auto &st = st::infoSharedMediaButton;
|
const auto &st = st::infoSharedMediaButton;
|
||||||
|
|
||||||
|
@ -2867,24 +2888,27 @@ object_ptr<Ui::RpWidget> SetupChannelMembersAndManage(
|
||||||
[=] { controller->showSection(Info::ChannelEarn::Make(peer)); },
|
[=] { controller->showSection(Info::ChannelEarn::Make(peer)); },
|
||||||
nullptr);
|
nullptr);
|
||||||
|
|
||||||
const auto credits = channel->session().credits().balance(
|
|
||||||
channel->id).whole();
|
|
||||||
const auto currency = channel->session().credits().balanceCurrency(
|
|
||||||
channel->id);
|
|
||||||
auto creditsText = (credits > 0)
|
|
||||||
? Ui::Text::SingleCustomEmoji(Ui::kCreditsCurrency)
|
|
||||||
.append(QChar(' '))
|
|
||||||
.append(QString::number(credits))
|
|
||||||
: TextWithEntities();
|
|
||||||
auto currencyText = (currency > 0)
|
|
||||||
? Ui::Text::SingleCustomEmoji("_")
|
|
||||||
.append(QChar(' '))
|
|
||||||
.append(Info::ChannelEarn::MajorPart(currency))
|
|
||||||
.append(Info::ChannelEarn::MinorPart(currency))
|
|
||||||
: TextWithEntities();
|
|
||||||
::Settings::CreateRightLabel(
|
::Settings::CreateRightLabel(
|
||||||
button->entity(),
|
button->entity(),
|
||||||
currencyText.append(QChar(' ')).append(std::move(creditsText)),
|
rpl::combine(
|
||||||
|
std::move(creditsValue),
|
||||||
|
std::move(currencyValue)
|
||||||
|
) | rpl::map([](uint64 credits, uint64 currency) {
|
||||||
|
auto creditsText = (credits > 0)
|
||||||
|
? Ui::Text::SingleCustomEmoji(Ui::kCreditsCurrency)
|
||||||
|
.append(QChar(' '))
|
||||||
|
.append(QString::number(credits))
|
||||||
|
: TextWithEntities();
|
||||||
|
auto currencyText = (currency > 0)
|
||||||
|
? Ui::Text::SingleCustomEmoji("_")
|
||||||
|
.append(QChar(' '))
|
||||||
|
.append(Info::ChannelEarn::MajorPart(currency))
|
||||||
|
.append(Info::ChannelEarn::MinorPart(currency))
|
||||||
|
: TextWithEntities();
|
||||||
|
return currencyText
|
||||||
|
.append(QChar(' '))
|
||||||
|
.append(std::move(creditsText));
|
||||||
|
}),
|
||||||
st,
|
st,
|
||||||
tr::lng_manage_peer_bot_balance(),
|
tr::lng_manage_peer_bot_balance(),
|
||||||
context);
|
context);
|
||||||
|
|
Loading…
Add table
Reference in a new issue