mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 13:47:05 +02:00
Added ability to display subscription info in ReceiptCreditsBox.
This commit is contained in:
parent
4760337958
commit
32e8ed93e2
10 changed files with 135 additions and 41 deletions
|
@ -1642,6 +1642,9 @@ void AddCreditsHistoryEntryTable(
|
|||
not_null<Window::SessionNavigation*> controller,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
const Data::CreditsHistoryEntry &entry) {
|
||||
if (!entry) {
|
||||
return;
|
||||
}
|
||||
auto table = container->add(
|
||||
object_ptr<Ui::TableLayout>(
|
||||
container,
|
||||
|
@ -1757,3 +1760,33 @@ void AddCreditsHistoryEntryTable(
|
|||
Ui::Text::Link(entry.successLink, entry.successLink)));
|
||||
}
|
||||
}
|
||||
|
||||
void AddSubscriptionEntryTable(
|
||||
not_null<Window::SessionNavigation*> controller,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
const Data::SubscriptionEntry &s) {
|
||||
if (!s) {
|
||||
return;
|
||||
}
|
||||
auto table = container->add(
|
||||
object_ptr<Ui::TableLayout>(
|
||||
container,
|
||||
st::giveawayGiftCodeTable),
|
||||
st::giveawayGiftCodeTableMargin);
|
||||
const auto peerId = PeerId(s.barePeerId);
|
||||
AddTableRow(
|
||||
table,
|
||||
tr::lng_credits_subscription_row_to(),
|
||||
controller,
|
||||
peerId);
|
||||
if (!s.until.isNull()) {
|
||||
AddTableRow(
|
||||
table,
|
||||
s.expired
|
||||
? tr::lng_credits_subscription_row_next_none()
|
||||
: s.cancelled
|
||||
? tr::lng_credits_subscription_row_next_off()
|
||||
: tr::lng_credits_subscription_row_next_on(),
|
||||
rpl::single(Ui::Text::WithEntities(langDateTime(s.until))));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ namespace Data {
|
|||
struct CreditsHistoryEntry;
|
||||
struct GiveawayStart;
|
||||
struct GiveawayResults;
|
||||
struct SubscriptionEntry;
|
||||
} // namespace Data
|
||||
|
||||
namespace Ui {
|
||||
|
@ -78,3 +79,8 @@ void AddCreditsHistoryEntryTable(
|
|||
not_null<Window::SessionNavigation*> controller,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
const Data::CreditsHistoryEntry &entry);
|
||||
|
||||
void AddSubscriptionEntryTable(
|
||||
not_null<Window::SessionNavigation*> controller,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
const Data::SubscriptionEntry &s);
|
||||
|
|
|
@ -353,11 +353,14 @@ void InnerWidget::fillHistory() {
|
|||
}, inner->lifetime());
|
||||
|
||||
const auto controller = _controller->parentController();
|
||||
const auto entryClicked = [=](const Data::CreditsHistoryEntry &e) {
|
||||
const auto entryClicked = [=](
|
||||
const Data::CreditsHistoryEntry &e,
|
||||
const Data::SubscriptionEntry &s) {
|
||||
controller->uiShow()->show(Box(
|
||||
::Settings::ReceiptCreditsBox,
|
||||
controller,
|
||||
e));
|
||||
e,
|
||||
s));
|
||||
};
|
||||
|
||||
Info::Statistics::AddCreditsHistoryList(
|
||||
|
|
|
@ -1404,11 +1404,13 @@ void InnerWidget::fill() {
|
|||
const auto show = controller->uiShow();
|
||||
const auto premiumBot = _peer->owner().peer(data.premiumBotId);
|
||||
const auto entryClicked = [=](
|
||||
const Data::CreditsHistoryEntry &e) {
|
||||
const Data::CreditsHistoryEntry &e,
|
||||
const Data::SubscriptionEntry &s) {
|
||||
show->show(Box(
|
||||
::Settings::ReceiptCreditsBox,
|
||||
controller,
|
||||
e));
|
||||
e,
|
||||
s));
|
||||
};
|
||||
|
||||
Info::Statistics::AddCreditsHistoryList(
|
||||
|
|
|
@ -133,7 +133,7 @@ struct BoostsDescriptor final {
|
|||
|
||||
struct CreditsDescriptor final {
|
||||
Data::CreditsStatusSlice firstSlice;
|
||||
Fn<void(const Data::CreditsHistoryEntry &)> entryClickedCallback;
|
||||
Clicked entryClickedCallback;
|
||||
not_null<PeerData*> peer;
|
||||
bool in = false;
|
||||
bool out = false;
|
||||
|
@ -980,7 +980,7 @@ private:
|
|||
void applySlice(const Data::CreditsStatusSlice &slice);
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
Fn<void(const Data::CreditsHistoryEntry &)> _entryClickedCallback;
|
||||
Clicked _entryClickedCallback;
|
||||
|
||||
Api::CreditsHistory _api;
|
||||
Data::CreditsStatusSlice _firstSlice;
|
||||
|
@ -1066,8 +1066,8 @@ void CreditsController::applySlice(const Data::CreditsStatusSlice &slice) {
|
|||
|
||||
void CreditsController::rowClicked(not_null<PeerListRow*> row) {
|
||||
if (_entryClickedCallback) {
|
||||
_entryClickedCallback(
|
||||
static_cast<const CreditsRow*>(row.get())->entry());
|
||||
const auto r = static_cast<const CreditsRow*>(row.get());
|
||||
_entryClickedCallback(r->entry(), r->subscription());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1230,7 +1230,7 @@ void AddCreditsHistoryList(
|
|||
std::shared_ptr<Main::SessionShow> show,
|
||||
const Data::CreditsStatusSlice &firstSlice,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
Fn<void(const Data::CreditsHistoryEntry &)> callback,
|
||||
Clicked callback,
|
||||
not_null<PeerData*> bot,
|
||||
bool in,
|
||||
bool out) {
|
||||
|
|
|
@ -20,6 +20,7 @@ struct CreditsHistoryEntry;
|
|||
struct CreditsStatusSlice;
|
||||
struct PublicForwardsSlice;
|
||||
struct RecentPostId;
|
||||
struct SubscriptionEntry;
|
||||
struct SupergroupStatistics;
|
||||
} // namespace Data
|
||||
|
||||
|
@ -50,11 +51,14 @@ void AddBoostsList(
|
|||
not_null<PeerData*> peer,
|
||||
rpl::producer<QString> title);
|
||||
|
||||
using Clicked = Fn<void(
|
||||
const Data::CreditsHistoryEntry &,
|
||||
const Data::SubscriptionEntry &)>;
|
||||
void AddCreditsHistoryList(
|
||||
std::shared_ptr<Main::SessionShow> show,
|
||||
const Data::CreditsStatusSlice &firstSlice,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
Fn<void(const Data::CreditsHistoryEntry &)> entryClickedCallback,
|
||||
Clicked entryClickedCallback,
|
||||
not_null<PeerData*> peer,
|
||||
bool in,
|
||||
bool out);
|
||||
|
|
|
@ -102,7 +102,8 @@ void ProcessCreditsReceipt(
|
|||
controller->uiShow()->show(Box(
|
||||
Settings::ReceiptCreditsBox,
|
||||
controller,
|
||||
entry));
|
||||
entry,
|
||||
Data::SubscriptionEntry{}));
|
||||
controller->window().activate();
|
||||
}
|
||||
|
||||
|
|
|
@ -150,11 +150,14 @@ void Credits::setupSubscriptions(not_null<Ui::VerticalLayout*> container) {
|
|||
object_ptr<Ui::VerticalLayout>(inner)));
|
||||
|
||||
const auto controller = _controller->parentController();
|
||||
const auto entryClicked = [=](const Data::CreditsHistoryEntry &e) {
|
||||
const auto entryClicked = [=](
|
||||
const Data::CreditsHistoryEntry &e,
|
||||
const Data::SubscriptionEntry &s) {
|
||||
controller->uiShow()->show(Box(
|
||||
ReceiptCreditsBox,
|
||||
controller,
|
||||
e));
|
||||
e,
|
||||
s));
|
||||
};
|
||||
|
||||
Info::Statistics::AddCreditsHistoryList(
|
||||
|
@ -280,11 +283,14 @@ void Credits::setupHistory(not_null<Ui::VerticalLayout*> container) {
|
|||
}, inner->lifetime());
|
||||
|
||||
const auto controller = _controller->parentController();
|
||||
const auto entryClicked = [=](const Data::CreditsHistoryEntry &e) {
|
||||
const auto entryClicked = [=](
|
||||
const Data::CreditsHistoryEntry &e,
|
||||
const Data::SubscriptionEntry &s) {
|
||||
controller->uiShow()->show(Box(
|
||||
ReceiptCreditsBox,
|
||||
controller,
|
||||
e));
|
||||
e,
|
||||
s));
|
||||
};
|
||||
|
||||
Info::Statistics::AddCreditsHistoryList(
|
||||
|
|
|
@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_file_origin.h"
|
||||
#include "data/data_photo_media.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_subscriptions.h"
|
||||
#include "data/data_user.h"
|
||||
#include "data/stickers/data_custom_emoji.h"
|
||||
#include "history/history.h"
|
||||
|
@ -440,12 +441,11 @@ not_null<Ui::RpWidget*> AddBalanceWidget(
|
|||
void ReceiptCreditsBox(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
not_null<Window::SessionController*> controller,
|
||||
const Data::CreditsHistoryEntry &e) {
|
||||
const Data::CreditsHistoryEntry &e,
|
||||
const Data::SubscriptionEntry &s) {
|
||||
box->setStyle(st::giveawayGiftCodeBox);
|
||||
box->setNoContentMargin(true);
|
||||
|
||||
const auto star = Ui::GenerateStars(st::creditsTopupButton.height, 1);
|
||||
|
||||
const auto content = box->verticalLayout();
|
||||
Ui::AddSkip(content);
|
||||
Ui::AddSkip(content);
|
||||
|
@ -455,7 +455,9 @@ void ReceiptCreditsBox(
|
|||
|
||||
const auto &stUser = st::boostReplaceUserpic;
|
||||
const auto session = &controller->session();
|
||||
const auto peer = (e.peerType == Type::PremiumBot)
|
||||
const auto peer = (s.barePeerId)
|
||||
? session->data().peer(PeerId(s.barePeerId)).get()
|
||||
: (e.peerType == Type::PremiumBot)
|
||||
? nullptr
|
||||
: e.barePeerId
|
||||
? session->data().peer(PeerId(e.barePeerId)).get()
|
||||
|
@ -548,7 +550,9 @@ void ReceiptCreditsBox(
|
|||
box,
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
box,
|
||||
rpl::single(!e.subscriptionUntil.isNull()
|
||||
rpl::single(!s.until.isNull()
|
||||
? tr::lng_credits_box_subscription_title(tr::now)
|
||||
: !e.subscriptionUntil.isNull()
|
||||
? tr::lng_credits_box_history_entry_subscription(tr::now)
|
||||
: !e.title.isEmpty()
|
||||
? e.title
|
||||
|
@ -564,10 +568,7 @@ void ReceiptCreditsBox(
|
|||
{
|
||||
constexpr auto kMinus = QChar(0x2212);
|
||||
auto &lifetime = content->lifetime();
|
||||
const auto text = lifetime.make_state<Ui::Text::String>(
|
||||
st::semiboldTextStyle,
|
||||
(e.in ? u"+"_q : e.gift ? QString() : QString(kMinus))
|
||||
+ Lang::FormatCountDecimal(std::abs(int64(e.credits))));
|
||||
const auto text = lifetime.make_state<Ui::Text::String>();
|
||||
const auto roundedText = e.refunded
|
||||
? tr::lng_channel_earn_history_return(tr::now)
|
||||
: e.pending
|
||||
|
@ -584,25 +585,50 @@ void ReceiptCreditsBox(
|
|||
const auto amount = content->add(
|
||||
object_ptr<Ui::FixedHeightWidget>(
|
||||
content,
|
||||
star.height() / style::DevicePixelRatio()));
|
||||
st::defaultTextStyle.font->height));
|
||||
const auto context = Core::MarkedTextContext{
|
||||
.session = session,
|
||||
.customEmojiRepaint = [=] { amount->update(); },
|
||||
};
|
||||
if (s) {
|
||||
text->setMarkedText(
|
||||
st::defaultTextStyle,
|
||||
tr::lng_credits_subscription_subtitle(
|
||||
tr::now,
|
||||
lt_emoji,
|
||||
session->data().customEmojiManager().creditsEmoji(),
|
||||
lt_cost,
|
||||
{ QString::number(s.subscription.credits) },
|
||||
Ui::Text::WithEntities),
|
||||
kMarkupTextOptions,
|
||||
context);
|
||||
} else {
|
||||
auto t = TextWithEntities()
|
||||
.append(e.in ? u"+"_q : e.gift ? QString() : QString(kMinus))
|
||||
.append(Lang::FormatCountDecimal(std::abs(int64(e.credits))))
|
||||
.append(QChar(' '))
|
||||
.append(session->data().customEmojiManager().creditsEmoji());
|
||||
text->setMarkedText(
|
||||
st::semiboldTextStyle,
|
||||
std::move(t),
|
||||
kMarkupTextOptions,
|
||||
context);
|
||||
}
|
||||
const auto font = text->style()->font;
|
||||
const auto roundedFont = st::defaultTextStyle.font;
|
||||
const auto starWidth = star.width()
|
||||
/ style::DevicePixelRatio();
|
||||
const auto roundedSkip = roundedFont->spacew * 2;
|
||||
const auto roundedWidth = rounded
|
||||
? roundedFont->width(roundedText)
|
||||
+ roundedSkip
|
||||
+ roundedFont->height
|
||||
: 0;
|
||||
const auto fullWidth = text->maxWidth()
|
||||
+ font->spacew * 1
|
||||
+ starWidth
|
||||
+ roundedWidth;
|
||||
const auto fullWidth = text->maxWidth() + roundedWidth;
|
||||
amount->paintRequest(
|
||||
) | rpl::start_with_next([=] {
|
||||
auto p = Painter(amount);
|
||||
p.setPen(e.pending
|
||||
p.setPen(s
|
||||
? st::windowSubTextFg
|
||||
: e.pending
|
||||
? st::creditsStroke
|
||||
: e.in
|
||||
? st::boxTextFgGood
|
||||
|
@ -617,10 +643,6 @@ void ReceiptCreditsBox(
|
|||
.outerWidth = amount->width(),
|
||||
.availableWidth = amount->width(),
|
||||
});
|
||||
p.drawImage(
|
||||
x + fullWidth - starWidth - roundedWidth,
|
||||
0,
|
||||
star);
|
||||
|
||||
if (rounded) {
|
||||
const auto roundedLeft = fullWidth
|
||||
|
@ -702,6 +724,7 @@ void ReceiptCreditsBox(
|
|||
Ui::AddSkip(content);
|
||||
|
||||
AddCreditsHistoryEntryTable(controller, content, e);
|
||||
AddSubscriptionEntryTable(controller, content, s);
|
||||
|
||||
Ui::AddSkip(content);
|
||||
|
||||
|
@ -713,11 +736,24 @@ void ReceiptCreditsBox(
|
|||
lt_link,
|
||||
tr::lng_payments_terms_link(
|
||||
) | Ui::Text::ToLink(
|
||||
tr::lng_credits_box_out_about_link(tr::now)
|
||||
),
|
||||
tr::lng_credits_box_out_about_link(tr::now)),
|
||||
Ui::Text::WithEntities),
|
||||
st::creditsBoxAboutDivider)));
|
||||
|
||||
if (s) {
|
||||
Ui::AddSkip(content);
|
||||
box->addRow(object_ptr<Ui::CenterWrap<>>(
|
||||
box,
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
box,
|
||||
s.cancelled
|
||||
? tr::lng_credits_subscription_off_about()
|
||||
: tr::lng_credits_subscription_on_about(
|
||||
lt_date,
|
||||
rpl::single(langDayOfMonthFull(s.until.date()))),
|
||||
st::creditsBoxAboutDivider)));
|
||||
}
|
||||
|
||||
Ui::AddSkip(content);
|
||||
|
||||
if (e.peerType == Data::CreditsHistoryEntry::PeerType::PremiumBot) {
|
||||
|
@ -782,7 +818,7 @@ void GiftedCreditsBox(
|
|||
.peerType = (anonymous ? PeerType::Fragment : PeerType::Peer),
|
||||
.in = received,
|
||||
.gift = true,
|
||||
});
|
||||
}, {});
|
||||
}
|
||||
|
||||
void ShowRefundInfoBox(
|
||||
|
@ -808,7 +844,8 @@ void ShowRefundInfoBox(
|
|||
controller->show(Box(
|
||||
::Settings::ReceiptCreditsBox,
|
||||
controller,
|
||||
info));
|
||||
info,
|
||||
Data::SubscriptionEntry{}));
|
||||
}
|
||||
|
||||
object_ptr<Ui::RpWidget> GenericEntryPhoto(
|
||||
|
|
|
@ -14,6 +14,7 @@ class PeerData;
|
|||
|
||||
namespace Data {
|
||||
struct CreditsHistoryEntry;
|
||||
struct SubscriptionEntry;
|
||||
} // namespace Data
|
||||
|
||||
namespace Main {
|
||||
|
@ -57,7 +58,8 @@ void AddWithdrawalWidget(
|
|||
void ReceiptCreditsBox(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
not_null<Window::SessionController*> controller,
|
||||
const Data::CreditsHistoryEntry &e);
|
||||
const Data::CreditsHistoryEntry &e,
|
||||
const Data::SubscriptionEntry &s);
|
||||
void GiftedCreditsBox(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
not_null<Window::SessionController*> controller,
|
||||
|
|
Loading…
Add table
Reference in a new issue