mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added credits balance to profile section of owned bots.
This commit is contained in:
parent
9716a901d1
commit
d56f3cfecf
2 changed files with 63 additions and 2 deletions
|
@ -459,6 +459,7 @@ infoProfileLabeledButtonQr: IconButton(infoProfileLabeledButtonCopy) {
|
||||||
|
|
||||||
infoIconInformation: icon {{ "info/info_information", infoIconFg }};
|
infoIconInformation: icon {{ "info/info_information", infoIconFg }};
|
||||||
infoIconAddMember: icon {{ "info/info_add_member", infoIconFg }};
|
infoIconAddMember: icon {{ "info/info_add_member", infoIconFg }};
|
||||||
|
infoIconBotBalance: icon {{ "menu/earn", infoIconFg, point(5px, 5px) }};
|
||||||
infoIconNotifications: icon {{ "info/info_notifications", infoIconFg }};
|
infoIconNotifications: icon {{ "info/info_notifications", infoIconFg }};
|
||||||
infoIconMediaPhoto: icon {{ "info/info_media_photo", infoIconFg }};
|
infoIconMediaPhoto: icon {{ "info/info_media_photo", infoIconFg }};
|
||||||
infoIconMediaVideo: icon {{ "info/info_media_video", infoIconFg }};
|
infoIconMediaVideo: icon {{ "info/info_media_video", infoIconFg }};
|
||||||
|
|
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "api/api_blocked_peers.h"
|
#include "api/api_blocked_peers.h"
|
||||||
#include "api/api_chat_participants.h"
|
#include "api/api_chat_participants.h"
|
||||||
|
#include "api/api_credits.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "base/options.h"
|
#include "base/options.h"
|
||||||
#include "base/timer_rpl.h"
|
#include "base/timer_rpl.h"
|
||||||
|
@ -21,8 +22,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "boxes/translate_box.h"
|
#include "boxes/translate_box.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "core/click_handler_types.h"
|
#include "core/click_handler_types.h"
|
||||||
|
#include "core/ui_integration.h"
|
||||||
#include "data/business/data_business_common.h"
|
#include "data/business/data_business_common.h"
|
||||||
#include "data/business/data_business_info.h"
|
#include "data/business/data_business_info.h"
|
||||||
|
#include "data/components/credits.h"
|
||||||
#include "data/data_changes.h"
|
#include "data/data_changes.h"
|
||||||
#include "data/data_channel.h"
|
#include "data/data_channel.h"
|
||||||
#include "data/data_chat.h"
|
#include "data/data_chat.h"
|
||||||
|
@ -32,12 +35,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
#include "data/notify/data_notify_settings.h"
|
#include "data/notify/data_notify_settings.h"
|
||||||
|
#include "data/stickers/data_custom_emoji.h"
|
||||||
#include "dialogs/ui/dialogs_layout.h"
|
#include "dialogs/ui/dialogs_layout.h"
|
||||||
#include "dialogs/ui/dialogs_message_view.h"
|
#include "dialogs/ui/dialogs_message_view.h"
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
#include "history/history_item.h"
|
#include "history/history_item.h"
|
||||||
#include "history/history_item_helpers.h"
|
#include "history/history_item_helpers.h"
|
||||||
#include "history/view/history_view_item_preview.h"
|
#include "history/view/history_view_item_preview.h"
|
||||||
|
#include "info/bot/earn/info_bot_earn_widget.h"
|
||||||
#include "info/info_controller.h"
|
#include "info/info_controller.h"
|
||||||
#include "info/info_memento.h"
|
#include "info/info_memento.h"
|
||||||
#include "info/profile/info_profile_icon.h"
|
#include "info/profile/info_profile_icon.h"
|
||||||
|
@ -75,6 +80,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "styles/style_info.h"
|
#include "styles/style_info.h"
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
#include "styles/style_menu_icons.h"
|
#include "styles/style_menu_icons.h"
|
||||||
|
#include "styles/style_settings.h" // settingsButtonRightSkip.
|
||||||
|
|
||||||
#include <QtGui/QGuiApplication>
|
#include <QtGui/QGuiApplication>
|
||||||
#include <QtGui/QClipboard>
|
#include <QtGui/QClipboard>
|
||||||
|
@ -825,6 +831,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addInviteToGroupAction(not_null<UserData*> user);
|
void addInviteToGroupAction(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);
|
||||||
|
@ -1830,8 +1837,7 @@ ActionsFiller::ActionsFiller(
|
||||||
, _peer(peer) {
|
, _peer(peer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionsFiller::addInviteToGroupAction(
|
void ActionsFiller::addInviteToGroupAction(not_null<UserData*> user) {
|
||||||
not_null<UserData*> user) {
|
|
||||||
const auto notEmpty = [](const QString &value) {
|
const auto notEmpty = [](const QString &value) {
|
||||||
return !value.isEmpty();
|
return !value.isEmpty();
|
||||||
};
|
};
|
||||||
|
@ -1855,6 +1861,59 @@ void ActionsFiller::addInviteToGroupAction(
|
||||||
about->finishAnimating();
|
about->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(),
|
||||||
|
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(),
|
||||||
|
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(
|
||||||
|
@ -2077,6 +2136,7 @@ void ActionsFiller::addJoinChannelAction(
|
||||||
|
|
||||||
void ActionsFiller::fillUserActions(not_null<UserData*> user) {
|
void ActionsFiller::fillUserActions(not_null<UserData*> user) {
|
||||||
if (user->isBot()) {
|
if (user->isBot()) {
|
||||||
|
addCreditsAction(user);
|
||||||
addInviteToGroupAction(user);
|
addInviteToGroupAction(user);
|
||||||
}
|
}
|
||||||
addShareContactAction(user);
|
addShareContactAction(user);
|
||||||
|
|
Loading…
Add table
Reference in a new issue