Added ability to display subscription info in ReceiptCreditsBox.

This commit is contained in:
23rd 2024-08-09 23:49:09 +03:00 committed by John Preston
parent 4760337958
commit 32e8ed93e2
10 changed files with 135 additions and 41 deletions

View file

@ -1642,6 +1642,9 @@ void AddCreditsHistoryEntryTable(
not_null<Window::SessionNavigation*> controller, not_null<Window::SessionNavigation*> controller,
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
const Data::CreditsHistoryEntry &entry) { const Data::CreditsHistoryEntry &entry) {
if (!entry) {
return;
}
auto table = container->add( auto table = container->add(
object_ptr<Ui::TableLayout>( object_ptr<Ui::TableLayout>(
container, container,
@ -1757,3 +1760,33 @@ void AddCreditsHistoryEntryTable(
Ui::Text::Link(entry.successLink, entry.successLink))); 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))));
}
}

View file

@ -19,6 +19,7 @@ namespace Data {
struct CreditsHistoryEntry; struct CreditsHistoryEntry;
struct GiveawayStart; struct GiveawayStart;
struct GiveawayResults; struct GiveawayResults;
struct SubscriptionEntry;
} // namespace Data } // namespace Data
namespace Ui { namespace Ui {
@ -78,3 +79,8 @@ void AddCreditsHistoryEntryTable(
not_null<Window::SessionNavigation*> controller, not_null<Window::SessionNavigation*> controller,
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
const Data::CreditsHistoryEntry &entry); const Data::CreditsHistoryEntry &entry);
void AddSubscriptionEntryTable(
not_null<Window::SessionNavigation*> controller,
not_null<Ui::VerticalLayout*> container,
const Data::SubscriptionEntry &s);

View file

@ -353,11 +353,14 @@ void InnerWidget::fillHistory() {
}, inner->lifetime()); }, inner->lifetime());
const auto controller = _controller->parentController(); 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( controller->uiShow()->show(Box(
::Settings::ReceiptCreditsBox, ::Settings::ReceiptCreditsBox,
controller, controller,
e)); e,
s));
}; };
Info::Statistics::AddCreditsHistoryList( Info::Statistics::AddCreditsHistoryList(

View file

@ -1404,11 +1404,13 @@ void InnerWidget::fill() {
const auto show = controller->uiShow(); const auto show = controller->uiShow();
const auto premiumBot = _peer->owner().peer(data.premiumBotId); const auto premiumBot = _peer->owner().peer(data.premiumBotId);
const auto entryClicked = [=]( const auto entryClicked = [=](
const Data::CreditsHistoryEntry &e) { const Data::CreditsHistoryEntry &e,
const Data::SubscriptionEntry &s) {
show->show(Box( show->show(Box(
::Settings::ReceiptCreditsBox, ::Settings::ReceiptCreditsBox,
controller, controller,
e)); e,
s));
}; };
Info::Statistics::AddCreditsHistoryList( Info::Statistics::AddCreditsHistoryList(

View file

@ -133,7 +133,7 @@ struct BoostsDescriptor final {
struct CreditsDescriptor final { struct CreditsDescriptor final {
Data::CreditsStatusSlice firstSlice; Data::CreditsStatusSlice firstSlice;
Fn<void(const Data::CreditsHistoryEntry &)> entryClickedCallback; Clicked entryClickedCallback;
not_null<PeerData*> peer; not_null<PeerData*> peer;
bool in = false; bool in = false;
bool out = false; bool out = false;
@ -980,7 +980,7 @@ private:
void applySlice(const Data::CreditsStatusSlice &slice); void applySlice(const Data::CreditsStatusSlice &slice);
const not_null<Main::Session*> _session; const not_null<Main::Session*> _session;
Fn<void(const Data::CreditsHistoryEntry &)> _entryClickedCallback; Clicked _entryClickedCallback;
Api::CreditsHistory _api; Api::CreditsHistory _api;
Data::CreditsStatusSlice _firstSlice; Data::CreditsStatusSlice _firstSlice;
@ -1066,8 +1066,8 @@ void CreditsController::applySlice(const Data::CreditsStatusSlice &slice) {
void CreditsController::rowClicked(not_null<PeerListRow*> row) { void CreditsController::rowClicked(not_null<PeerListRow*> row) {
if (_entryClickedCallback) { if (_entryClickedCallback) {
_entryClickedCallback( const auto r = static_cast<const CreditsRow*>(row.get());
static_cast<const CreditsRow*>(row.get())->entry()); _entryClickedCallback(r->entry(), r->subscription());
} }
} }
@ -1230,7 +1230,7 @@ void AddCreditsHistoryList(
std::shared_ptr<Main::SessionShow> show, std::shared_ptr<Main::SessionShow> show,
const Data::CreditsStatusSlice &firstSlice, const Data::CreditsStatusSlice &firstSlice,
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
Fn<void(const Data::CreditsHistoryEntry &)> callback, Clicked callback,
not_null<PeerData*> bot, not_null<PeerData*> bot,
bool in, bool in,
bool out) { bool out) {

View file

@ -20,6 +20,7 @@ struct CreditsHistoryEntry;
struct CreditsStatusSlice; struct CreditsStatusSlice;
struct PublicForwardsSlice; struct PublicForwardsSlice;
struct RecentPostId; struct RecentPostId;
struct SubscriptionEntry;
struct SupergroupStatistics; struct SupergroupStatistics;
} // namespace Data } // namespace Data
@ -50,11 +51,14 @@ void AddBoostsList(
not_null<PeerData*> peer, not_null<PeerData*> peer,
rpl::producer<QString> title); rpl::producer<QString> title);
using Clicked = Fn<void(
const Data::CreditsHistoryEntry &,
const Data::SubscriptionEntry &)>;
void AddCreditsHistoryList( void AddCreditsHistoryList(
std::shared_ptr<Main::SessionShow> show, std::shared_ptr<Main::SessionShow> show,
const Data::CreditsStatusSlice &firstSlice, const Data::CreditsStatusSlice &firstSlice,
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
Fn<void(const Data::CreditsHistoryEntry &)> entryClickedCallback, Clicked entryClickedCallback,
not_null<PeerData*> peer, not_null<PeerData*> peer,
bool in, bool in,
bool out); bool out);

View file

@ -102,7 +102,8 @@ void ProcessCreditsReceipt(
controller->uiShow()->show(Box( controller->uiShow()->show(Box(
Settings::ReceiptCreditsBox, Settings::ReceiptCreditsBox,
controller, controller,
entry)); entry,
Data::SubscriptionEntry{}));
controller->window().activate(); controller->window().activate();
} }

View file

@ -150,11 +150,14 @@ void Credits::setupSubscriptions(not_null<Ui::VerticalLayout*> container) {
object_ptr<Ui::VerticalLayout>(inner))); object_ptr<Ui::VerticalLayout>(inner)));
const auto controller = _controller->parentController(); 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( controller->uiShow()->show(Box(
ReceiptCreditsBox, ReceiptCreditsBox,
controller, controller,
e)); e,
s));
}; };
Info::Statistics::AddCreditsHistoryList( Info::Statistics::AddCreditsHistoryList(
@ -280,11 +283,14 @@ void Credits::setupHistory(not_null<Ui::VerticalLayout*> container) {
}, inner->lifetime()); }, inner->lifetime());
const auto controller = _controller->parentController(); 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( controller->uiShow()->show(Box(
ReceiptCreditsBox, ReceiptCreditsBox,
controller, controller,
e)); e,
s));
}; };
Info::Statistics::AddCreditsHistoryList( Info::Statistics::AddCreditsHistoryList(

View file

@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_file_origin.h" #include "data/data_file_origin.h"
#include "data/data_photo_media.h" #include "data/data_photo_media.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_subscriptions.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "data/stickers/data_custom_emoji.h" #include "data/stickers/data_custom_emoji.h"
#include "history/history.h" #include "history/history.h"
@ -440,12 +441,11 @@ not_null<Ui::RpWidget*> AddBalanceWidget(
void ReceiptCreditsBox( void ReceiptCreditsBox(
not_null<Ui::GenericBox*> box, not_null<Ui::GenericBox*> box,
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
const Data::CreditsHistoryEntry &e) { const Data::CreditsHistoryEntry &e,
const Data::SubscriptionEntry &s) {
box->setStyle(st::giveawayGiftCodeBox); box->setStyle(st::giveawayGiftCodeBox);
box->setNoContentMargin(true); box->setNoContentMargin(true);
const auto star = Ui::GenerateStars(st::creditsTopupButton.height, 1);
const auto content = box->verticalLayout(); const auto content = box->verticalLayout();
Ui::AddSkip(content); Ui::AddSkip(content);
Ui::AddSkip(content); Ui::AddSkip(content);
@ -455,7 +455,9 @@ void ReceiptCreditsBox(
const auto &stUser = st::boostReplaceUserpic; const auto &stUser = st::boostReplaceUserpic;
const auto session = &controller->session(); 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 ? nullptr
: e.barePeerId : e.barePeerId
? session->data().peer(PeerId(e.barePeerId)).get() ? session->data().peer(PeerId(e.barePeerId)).get()
@ -548,7 +550,9 @@ void ReceiptCreditsBox(
box, box,
object_ptr<Ui::FlatLabel>( object_ptr<Ui::FlatLabel>(
box, 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) ? tr::lng_credits_box_history_entry_subscription(tr::now)
: !e.title.isEmpty() : !e.title.isEmpty()
? e.title ? e.title
@ -564,10 +568,7 @@ void ReceiptCreditsBox(
{ {
constexpr auto kMinus = QChar(0x2212); constexpr auto kMinus = QChar(0x2212);
auto &lifetime = content->lifetime(); auto &lifetime = content->lifetime();
const auto text = lifetime.make_state<Ui::Text::String>( 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 roundedText = e.refunded const auto roundedText = e.refunded
? tr::lng_channel_earn_history_return(tr::now) ? tr::lng_channel_earn_history_return(tr::now)
: e.pending : e.pending
@ -584,25 +585,50 @@ void ReceiptCreditsBox(
const auto amount = content->add( const auto amount = content->add(
object_ptr<Ui::FixedHeightWidget>( object_ptr<Ui::FixedHeightWidget>(
content, 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 font = text->style()->font;
const auto roundedFont = st::defaultTextStyle.font; const auto roundedFont = st::defaultTextStyle.font;
const auto starWidth = star.width()
/ style::DevicePixelRatio();
const auto roundedSkip = roundedFont->spacew * 2; const auto roundedSkip = roundedFont->spacew * 2;
const auto roundedWidth = rounded const auto roundedWidth = rounded
? roundedFont->width(roundedText) ? roundedFont->width(roundedText)
+ roundedSkip + roundedSkip
+ roundedFont->height + roundedFont->height
: 0; : 0;
const auto fullWidth = text->maxWidth() const auto fullWidth = text->maxWidth() + roundedWidth;
+ font->spacew * 1
+ starWidth
+ roundedWidth;
amount->paintRequest( amount->paintRequest(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
auto p = Painter(amount); auto p = Painter(amount);
p.setPen(e.pending p.setPen(s
? st::windowSubTextFg
: e.pending
? st::creditsStroke ? st::creditsStroke
: e.in : e.in
? st::boxTextFgGood ? st::boxTextFgGood
@ -617,10 +643,6 @@ void ReceiptCreditsBox(
.outerWidth = amount->width(), .outerWidth = amount->width(),
.availableWidth = amount->width(), .availableWidth = amount->width(),
}); });
p.drawImage(
x + fullWidth - starWidth - roundedWidth,
0,
star);
if (rounded) { if (rounded) {
const auto roundedLeft = fullWidth const auto roundedLeft = fullWidth
@ -702,6 +724,7 @@ void ReceiptCreditsBox(
Ui::AddSkip(content); Ui::AddSkip(content);
AddCreditsHistoryEntryTable(controller, content, e); AddCreditsHistoryEntryTable(controller, content, e);
AddSubscriptionEntryTable(controller, content, s);
Ui::AddSkip(content); Ui::AddSkip(content);
@ -713,11 +736,24 @@ void ReceiptCreditsBox(
lt_link, lt_link,
tr::lng_payments_terms_link( tr::lng_payments_terms_link(
) | Ui::Text::ToLink( ) | Ui::Text::ToLink(
tr::lng_credits_box_out_about_link(tr::now) tr::lng_credits_box_out_about_link(tr::now)),
),
Ui::Text::WithEntities), Ui::Text::WithEntities),
st::creditsBoxAboutDivider))); 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); Ui::AddSkip(content);
if (e.peerType == Data::CreditsHistoryEntry::PeerType::PremiumBot) { if (e.peerType == Data::CreditsHistoryEntry::PeerType::PremiumBot) {
@ -782,7 +818,7 @@ void GiftedCreditsBox(
.peerType = (anonymous ? PeerType::Fragment : PeerType::Peer), .peerType = (anonymous ? PeerType::Fragment : PeerType::Peer),
.in = received, .in = received,
.gift = true, .gift = true,
}); }, {});
} }
void ShowRefundInfoBox( void ShowRefundInfoBox(
@ -808,7 +844,8 @@ void ShowRefundInfoBox(
controller->show(Box( controller->show(Box(
::Settings::ReceiptCreditsBox, ::Settings::ReceiptCreditsBox,
controller, controller,
info)); info,
Data::SubscriptionEntry{}));
} }
object_ptr<Ui::RpWidget> GenericEntryPhoto( object_ptr<Ui::RpWidget> GenericEntryPhoto(

View file

@ -14,6 +14,7 @@ class PeerData;
namespace Data { namespace Data {
struct CreditsHistoryEntry; struct CreditsHistoryEntry;
struct SubscriptionEntry;
} // namespace Data } // namespace Data
namespace Main { namespace Main {
@ -57,7 +58,8 @@ void AddWithdrawalWidget(
void ReceiptCreditsBox( void ReceiptCreditsBox(
not_null<Ui::GenericBox*> box, not_null<Ui::GenericBox*> box,
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
const Data::CreditsHistoryEntry &e); const Data::CreditsHistoryEntry &e,
const Data::SubscriptionEntry &s);
void GiftedCreditsBox( void GiftedCreditsBox(
not_null<Ui::GenericBox*> box, not_null<Ui::GenericBox*> box,
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,