mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added subsection title to earn buttons in profile of owned bots.
This commit is contained in:
parent
dbb0a5ad28
commit
187139473d
1 changed files with 154 additions and 128 deletions
|
@ -775,6 +775,139 @@ template <typename Text, typename ToggleOn, typename Callback>
|
||||||
st));
|
st));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpl::producer<uint64> AddCurrencyAction(
|
||||||
|
not_null<UserData*> user,
|
||||||
|
not_null<Ui::VerticalLayout*> wrap,
|
||||||
|
not_null<Controller*> controller) {
|
||||||
|
struct State final {
|
||||||
|
rpl::variable<uint64> balance;
|
||||||
|
};
|
||||||
|
const auto state = wrap->lifetime().make_state<State>();
|
||||||
|
const auto parentController = controller->parentController();
|
||||||
|
const auto wrapButton = AddActionButton(
|
||||||
|
wrap,
|
||||||
|
tr::lng_manage_peer_bot_balance_currency(),
|
||||||
|
state->balance.value() | rpl::map(rpl::mappers::_1 > 0),
|
||||||
|
[=] { parentController->showSection(Info::ChannelEarn::Make(user)); },
|
||||||
|
&st::infoIconBotBalance);
|
||||||
|
const auto balance = user->session().credits().balanceCurrency(user->id);
|
||||||
|
if (balance) {
|
||||||
|
state->balance = balance;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const auto weak = Ui::MakeWeak(wrap);
|
||||||
|
const auto currencyLoadLifetime
|
||||||
|
= std::make_shared<rpl::lifetime>();
|
||||||
|
const auto currencyLoad
|
||||||
|
= currencyLoadLifetime->make_state<Api::EarnStatistics>(user);
|
||||||
|
currencyLoad->request(
|
||||||
|
) | rpl::start_with_error_done([=](const QString &error) {
|
||||||
|
currencyLoadLifetime->destroy();
|
||||||
|
}, [=] {
|
||||||
|
if (const auto strong = weak.get()) {
|
||||||
|
state->balance = currencyLoad->data().currentBalance;
|
||||||
|
currencyLoadLifetime->destroy();
|
||||||
|
}
|
||||||
|
}, *currencyLoadLifetime);
|
||||||
|
}
|
||||||
|
const auto &st = st::infoSharedMediaButton;
|
||||||
|
const auto button = wrapButton->entity();
|
||||||
|
const auto name = Ui::CreateChild<Ui::FlatLabel>(button, st.rightLabel);
|
||||||
|
const auto icon = Ui::Text::SingleCustomEmoji(
|
||||||
|
user->owner().customEmojiManager().registerInternalEmoji(
|
||||||
|
Info::ChannelEarn::IconCurrency(
|
||||||
|
st.rightLabel,
|
||||||
|
st.rightLabel.textFg->c),
|
||||||
|
st::channelEarnCurrencyCommonMargins,
|
||||||
|
false));
|
||||||
|
name->show();
|
||||||
|
rpl::combine(
|
||||||
|
button->widthValue(),
|
||||||
|
tr::lng_manage_peer_bot_balance_currency(),
|
||||||
|
state->balance.value()
|
||||||
|
) | rpl::start_with_next([=, &st](
|
||||||
|
int width,
|
||||||
|
const QString &button,
|
||||||
|
uint64 balance) {
|
||||||
|
const auto available = width
|
||||||
|
- rect::m::sum::h(st.padding)
|
||||||
|
- st.style.font->width(button)
|
||||||
|
- st::settingsButtonRightSkip;
|
||||||
|
name->setMarkedText(
|
||||||
|
base::duplicate(icon)
|
||||||
|
.append(QChar(' '))
|
||||||
|
.append(Info::ChannelEarn::MajorPart(balance))
|
||||||
|
.append(Info::ChannelEarn::MinorPart(balance)),
|
||||||
|
Core::MarkedTextContext{
|
||||||
|
.session = &user->session(),
|
||||||
|
.customEmojiRepaint = [=] { name->update(); },
|
||||||
|
});
|
||||||
|
name->resizeToNaturalWidth(available);
|
||||||
|
name->moveToRight(st::settingsButtonRightSkip, st.padding.top());
|
||||||
|
}, name->lifetime());
|
||||||
|
name->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
|
wrapButton->finishAnimating();
|
||||||
|
return state->balance.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<uint64> AddCreditsAction(
|
||||||
|
not_null<UserData*> user,
|
||||||
|
not_null<Ui::VerticalLayout*> wrap,
|
||||||
|
not_null<Controller*> controller) {
|
||||||
|
struct State final {
|
||||||
|
rpl::variable<uint64> balance;
|
||||||
|
};
|
||||||
|
const auto state = wrap->lifetime().make_state<State>();
|
||||||
|
const auto parentController = controller->parentController();
|
||||||
|
const auto wrapButton = AddActionButton(
|
||||||
|
wrap,
|
||||||
|
tr::lng_manage_peer_bot_balance_credits(),
|
||||||
|
state->balance.value() | rpl::map(rpl::mappers::_1 > 0),
|
||||||
|
[=] { parentController->showSection(Info::BotEarn::Make(user)); },
|
||||||
|
&st::infoIconBotBalance);
|
||||||
|
if (const auto balance = user->session().credits().balance(user->id)) {
|
||||||
|
state->balance = balance;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const auto api = wrap->lifetime().make_state<Api::CreditsStatus>(
|
||||||
|
user);
|
||||||
|
api->request({}, [=](Data::CreditsStatusSlice data) {
|
||||||
|
state->balance = data.balance;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const auto &st = st::infoSharedMediaButton;
|
||||||
|
const auto button = wrapButton->entity();
|
||||||
|
const auto name = Ui::CreateChild<Ui::FlatLabel>(button, st.rightLabel);
|
||||||
|
const auto icon = user->owner().customEmojiManager().creditsEmoji();
|
||||||
|
name->show();
|
||||||
|
rpl::combine(
|
||||||
|
button->widthValue(),
|
||||||
|
tr::lng_manage_peer_bot_balance_credits(),
|
||||||
|
state->balance.value()
|
||||||
|
) | rpl::start_with_next([=, &st](
|
||||||
|
int width,
|
||||||
|
const QString &button,
|
||||||
|
uint64 balance) {
|
||||||
|
const auto available = width
|
||||||
|
- rect::m::sum::h(st.padding)
|
||||||
|
- st.style.font->width(button)
|
||||||
|
- st::settingsButtonRightSkip;
|
||||||
|
name->setMarkedText(
|
||||||
|
base::duplicate(icon)
|
||||||
|
.append(QChar(' '))
|
||||||
|
.append(QString::number(balance)),
|
||||||
|
Core::MarkedTextContext{
|
||||||
|
.session = &user->session(),
|
||||||
|
.customEmojiRepaint = [=] { name->update(); },
|
||||||
|
});
|
||||||
|
name->resizeToNaturalWidth(available);
|
||||||
|
name->moveToRight(st::settingsButtonRightSkip, st.padding.top());
|
||||||
|
}, name->lifetime());
|
||||||
|
name->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
|
wrapButton->finishAnimating();
|
||||||
|
return state->balance.value();
|
||||||
|
}
|
||||||
|
|
||||||
class DetailsFiller {
|
class DetailsFiller {
|
||||||
public:
|
public:
|
||||||
DetailsFiller(
|
DetailsFiller(
|
||||||
|
@ -838,9 +971,8 @@ public:
|
||||||
object_ptr<Ui::RpWidget> fill();
|
object_ptr<Ui::RpWidget> fill();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void addBalanceActions(not_null<UserData*> user);
|
||||||
void addInviteToGroupAction(not_null<UserData*> user);
|
void addInviteToGroupAction(not_null<UserData*> user);
|
||||||
void addCurrencyAction(not_null<UserData*> user);
|
|
||||||
void addCreditsAction(not_null<UserData*> user);
|
|
||||||
void addShareContactAction(not_null<UserData*> user);
|
void addShareContactAction(not_null<UserData*> user);
|
||||||
void addEditContactAction(not_null<UserData*> user);
|
void addEditContactAction(not_null<UserData*> user);
|
||||||
void addDeleteContactAction(not_null<UserData*> user);
|
void addDeleteContactAction(not_null<UserData*> user);
|
||||||
|
@ -1916,6 +2048,25 @@ ActionsFiller::ActionsFiller(
|
||||||
, _peer(peer) {
|
, _peer(peer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ActionsFiller::addBalanceActions(not_null<UserData*> user) {
|
||||||
|
const auto wrap = _wrap->add(
|
||||||
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||||
|
_wrap.data(),
|
||||||
|
object_ptr<Ui::VerticalLayout>(_wrap.data())));
|
||||||
|
const auto inner = wrap->entity();
|
||||||
|
Ui::AddSubsectionTitle(inner, tr::lng_manage_peer_bot_balance());
|
||||||
|
auto currencyBalance = AddCurrencyAction(user, inner, _controller);
|
||||||
|
auto creditsBalance = AddCreditsAction(user, inner, _controller);
|
||||||
|
Ui::AddSkip(inner);
|
||||||
|
Ui::AddDivider(inner);
|
||||||
|
Ui::AddSkip(inner);
|
||||||
|
wrap->toggleOn(
|
||||||
|
rpl::combine(
|
||||||
|
std::move(currencyBalance),
|
||||||
|
std::move(creditsBalance)
|
||||||
|
) | rpl::map((rpl::mappers::_1 + rpl::mappers::_2) > 0));
|
||||||
|
}
|
||||||
|
|
||||||
void ActionsFiller::addInviteToGroupAction(not_null<UserData*> user) {
|
void ActionsFiller::addInviteToGroupAction(not_null<UserData*> user) {
|
||||||
const auto notEmpty = [](const QString &value) {
|
const auto notEmpty = [](const QString &value) {
|
||||||
return !value.isEmpty();
|
return !value.isEmpty();
|
||||||
|
@ -1940,130 +2091,6 @@ void ActionsFiller::addInviteToGroupAction(not_null<UserData*> user) {
|
||||||
about->finishAnimating();
|
about->finishAnimating();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionsFiller::addCurrencyAction(not_null<UserData*> user) {
|
|
||||||
struct State final {
|
|
||||||
rpl::variable<uint64> balance;
|
|
||||||
};
|
|
||||||
const auto state = _wrap->lifetime().make_state<State>();
|
|
||||||
const auto controller = _controller->parentController();
|
|
||||||
const auto wrap = AddActionButton(
|
|
||||||
_wrap,
|
|
||||||
tr::lng_manage_peer_bot_balance_currency(),
|
|
||||||
state->balance.value() | rpl::map(rpl::mappers::_1 > 0),
|
|
||||||
[=] { controller->showSection(Info::ChannelEarn::Make(user)); },
|
|
||||||
&st::infoIconBotBalance);
|
|
||||||
const auto balance = user->session().credits().balanceCurrency(user->id);
|
|
||||||
if (balance) {
|
|
||||||
state->balance = balance;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
const auto weak = Ui::MakeWeak(_wrap.data());
|
|
||||||
const auto currencyLoadLifetime
|
|
||||||
= std::make_shared<rpl::lifetime>();
|
|
||||||
const auto currencyLoad
|
|
||||||
= currencyLoadLifetime->make_state<Api::EarnStatistics>(user);
|
|
||||||
currencyLoad->request(
|
|
||||||
) | rpl::start_with_error_done([=](const QString &error) {
|
|
||||||
currencyLoadLifetime->destroy();
|
|
||||||
}, [=] {
|
|
||||||
if (const auto strong = weak.get()) {
|
|
||||||
state->balance = currencyLoad->data().currentBalance;
|
|
||||||
currencyLoadLifetime->destroy();
|
|
||||||
}
|
|
||||||
}, *currencyLoadLifetime);
|
|
||||||
}
|
|
||||||
const auto &st = st::infoSharedMediaButton;
|
|
||||||
const auto button = wrap->entity();
|
|
||||||
const auto name = Ui::CreateChild<Ui::FlatLabel>(button, st.rightLabel);
|
|
||||||
const auto icon = Ui::Text::SingleCustomEmoji(
|
|
||||||
user->owner().customEmojiManager().registerInternalEmoji(
|
|
||||||
Info::ChannelEarn::IconCurrency(
|
|
||||||
st.rightLabel,
|
|
||||||
st.rightLabel.textFg->c),
|
|
||||||
st::channelEarnCurrencyCommonMargins,
|
|
||||||
false));
|
|
||||||
name->show();
|
|
||||||
rpl::combine(
|
|
||||||
button->widthValue(),
|
|
||||||
tr::lng_manage_peer_bot_balance_currency(),
|
|
||||||
state->balance.value()
|
|
||||||
) | rpl::start_with_next([=, &st](
|
|
||||||
int width,
|
|
||||||
const QString &button,
|
|
||||||
uint64 balance) {
|
|
||||||
const auto available = width
|
|
||||||
- rect::m::sum::h(st.padding)
|
|
||||||
- st.style.font->width(button)
|
|
||||||
- st::settingsButtonRightSkip;
|
|
||||||
name->setMarkedText(
|
|
||||||
base::duplicate(icon)
|
|
||||||
.append(QChar(' '))
|
|
||||||
.append(Info::ChannelEarn::MajorPart(balance))
|
|
||||||
.append(Info::ChannelEarn::MinorPart(balance)),
|
|
||||||
Core::MarkedTextContext{
|
|
||||||
.session = &user->session(),
|
|
||||||
.customEmojiRepaint = [=] { name->update(); },
|
|
||||||
});
|
|
||||||
name->resizeToNaturalWidth(available);
|
|
||||||
name->moveToRight(st::settingsButtonRightSkip, st.padding.top());
|
|
||||||
}, name->lifetime());
|
|
||||||
name->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
||||||
wrap->finishAnimating();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ActionsFiller::addCreditsAction(not_null<UserData*> user) {
|
|
||||||
struct State final {
|
|
||||||
rpl::variable<uint64> balance;
|
|
||||||
};
|
|
||||||
const auto state = _wrap->lifetime().make_state<State>();
|
|
||||||
const auto controller = _controller->parentController();
|
|
||||||
const auto wrap = AddActionButton(
|
|
||||||
_wrap,
|
|
||||||
tr::lng_manage_peer_bot_balance_credits(),
|
|
||||||
state->balance.value() | rpl::map(rpl::mappers::_1 > 0),
|
|
||||||
[=] { controller->showSection(Info::BotEarn::Make(user)); },
|
|
||||||
&st::infoIconBotBalance);
|
|
||||||
if (const auto balance = user->session().credits().balance(user->id)) {
|
|
||||||
state->balance = balance;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
const auto api = _wrap->lifetime().make_state<Api::CreditsStatus>(
|
|
||||||
user);
|
|
||||||
api->request({}, [=](Data::CreditsStatusSlice data) {
|
|
||||||
state->balance = data.balance;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const auto &st = st::infoSharedMediaButton;
|
|
||||||
const auto button = wrap->entity();
|
|
||||||
const auto name = Ui::CreateChild<Ui::FlatLabel>(button, st.rightLabel);
|
|
||||||
name->show();
|
|
||||||
rpl::combine(
|
|
||||||
button->widthValue(),
|
|
||||||
tr::lng_manage_peer_bot_balance_credits(),
|
|
||||||
state->balance.value()
|
|
||||||
) | rpl::start_with_next([=, &st](
|
|
||||||
int width,
|
|
||||||
const QString &button,
|
|
||||||
uint64 balance) {
|
|
||||||
const auto available = width
|
|
||||||
- rect::m::sum::h(st.padding)
|
|
||||||
- st.style.font->width(button)
|
|
||||||
- st::settingsButtonRightSkip;
|
|
||||||
name->setMarkedText(
|
|
||||||
user->owner().customEmojiManager().creditsEmoji()
|
|
||||||
.append(QChar(' '))
|
|
||||||
.append(QString::number(balance)),
|
|
||||||
Core::MarkedTextContext{
|
|
||||||
.session = &user->session(),
|
|
||||||
.customEmojiRepaint = [=] { name->update(); },
|
|
||||||
});
|
|
||||||
name->resizeToNaturalWidth(available);
|
|
||||||
name->moveToRight(st::settingsButtonRightSkip, st.padding.top());
|
|
||||||
}, name->lifetime());
|
|
||||||
name->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
||||||
wrap->finishAnimating();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ActionsFiller::addShareContactAction(not_null<UserData*> user) {
|
void ActionsFiller::addShareContactAction(not_null<UserData*> user) {
|
||||||
const auto controller = _controller->parentController();
|
const auto controller = _controller->parentController();
|
||||||
AddActionButton(
|
AddActionButton(
|
||||||
|
@ -2285,8 +2312,7 @@ void ActionsFiller::addJoinChannelAction(
|
||||||
|
|
||||||
void ActionsFiller::fillUserActions(not_null<UserData*> user) {
|
void ActionsFiller::fillUserActions(not_null<UserData*> user) {
|
||||||
if (user->isBot()) {
|
if (user->isBot()) {
|
||||||
addCurrencyAction(user);
|
addBalanceActions(user);
|
||||||
addCreditsAction(user);
|
|
||||||
addInviteToGroupAction(user);
|
addInviteToGroupAction(user);
|
||||||
}
|
}
|
||||||
addShareContactAction(user);
|
addShareContactAction(user);
|
||||||
|
|
Loading…
Add table
Reference in a new issue