Skip to content

Commit

Permalink
Added phrases to credits history entries when peer type is premium bot.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd authored and john-preston committed Jul 17, 2024
1 parent 4b9eb37 commit 4f7a124
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Telegram/Resources/langs/lang.strings
Original file line number Diff line number Diff line change
Expand Up @@ -2370,6 +2370,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_credits_box_history_entry_app_store" = "App Store";
"lng_credits_box_history_entry_fragment" = "Fragment";
"lng_credits_box_history_entry_ads" = "Ads Platform";
"lng_credits_box_history_entry_premium_bot" = "Stars Top-Up";
"lng_credits_box_history_entry_via_premium_bot" = "Premium Bot";
"lng_credits_box_history_entry_id" = "Transaction ID";
"lng_credits_box_history_entry_id_copied" = "Transaction ID copied to clipboard.";
"lng_credits_box_history_entry_success_date" = "Transaction date";
Expand Down
6 changes: 6 additions & 0 deletions Telegram/SourceFiles/boxes/gift_premium_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,12 @@ void AddCreditsHistoryEntryTable(
table,
tr::lng_credits_box_history_entry_via(),
tr::lng_credits_box_history_entry_ads(Ui::Text::RichLangValue));
} else if (entry.peerType == Type::PremiumBot) {
AddTableRow(
table,
tr::lng_credits_box_history_entry_via(),
tr::lng_credits_box_history_entry_via_premium_bot(
Ui::Text::RichLangValue));
}
if (!entry.id.isEmpty()) {
constexpr auto kOneLineCount = 18;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,6 @@ void CreditsController::applySlice(const Data::CreditsStatusSlice &slice) {
if (const auto peerId = PeerId(item.barePeerId)) {
const auto peer = session().data().peer(peerId);
return std::make_unique<CreditsRow>(peer, descriptor);
} else if (item.peerType == Type::PremiumBot) {
return std::make_unique<CreditsRow>(_premiumBot, descriptor);
} else {
return std::make_unique<CreditsRow>(descriptor);
}
Expand Down
29 changes: 28 additions & 1 deletion Telegram/SourceFiles/settings/settings_credits_graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ void ReceiptCreditsBox(
const auto &stUser = st::boostReplaceUserpic;
const auto session = &controller->session();
const auto peer = (e.peerType == Type::PremiumBot)
? premiumBot
? nullptr
: e.barePeerId
? session->data().peer(PeerId(e.barePeerId)).get()
: nullptr;
Expand Down Expand Up @@ -622,6 +622,33 @@ void ReceiptCreditsBox(

Ui::AddSkip(content);

if (e.peerType == Data::CreditsHistoryEntry::PeerType::PremiumBot) {
const auto widget = Ui::CreateChild<Ui::RpWidget>(content);
using ColoredMiniStars = Ui::Premium::ColoredMiniStars;
const auto stars = widget->lifetime().make_state<ColoredMiniStars>(
widget,
false,
Ui::Premium::MiniStars::Type::BiStars);
stars->setColorOverride(Ui::Premium::CreditsIconGradientStops());
widget->resize(
st::boxWidth - stUser.photoSize,
stUser.photoSize * 2);
content->sizeValue(
) | rpl::start_with_next([=](const QSize &size) {
widget->moveToLeft(stUser.photoSize / 2, 0);
const auto starsRect = Rect(widget->size());
stars->setPosition(starsRect.topLeft());
stars->setSize(starsRect.size());
widget->lower();
}, widget->lifetime());
widget->paintRequest(
) | rpl::start_with_next([=](const QRect &r) {
auto p = QPainter(widget);
p.fillRect(r, Qt::transparent);
stars->paint(p);
}, widget->lifetime());
}

const auto button = box->addButton(tr::lng_box_ok(), [=] {
box->closeBox();
});
Expand Down
21 changes: 17 additions & 4 deletions Telegram/SourceFiles/ui/effects/credits_graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,21 @@ not_null<MaskedInputField*> AddInputFieldForCredits(

PaintRoundImageCallback GenerateCreditsPaintUserpicCallback(
const Data::CreditsHistoryEntry &entry) {
using PeerType = Data::CreditsHistoryEntry::PeerType;
if (entry.peerType == PeerType::PremiumBot) {
const auto svg = std::make_shared<QSvgRenderer>(Ui::Premium::Svg());
return [=](Painter &p, int x, int y, int, int size) mutable {
const auto hq = PainterHighQualityEnabler(p);
p.setPen(Qt::NoPen);
{
auto gradient = QLinearGradient(x + size, y + size, x, y);
gradient.setStops(Ui::Premium::ButtonGradientStops());
p.setBrush(gradient);
}
p.drawEllipse(x, y, size, size);
svg->render(&p, QRectF(x, y, size, size) - Margins(size / 5.));
};
}
const auto bg = [&]() -> EmptyUserpic::BgColors {
switch (entry.peerType) {
case Data::CreditsHistoryEntry::PeerType::Peer:
Expand All @@ -218,10 +233,6 @@ PaintRoundImageCallback GenerateCreditsPaintUserpicCallback(
const auto userpic = std::make_shared<EmptyUserpic>(bg, QString());
return [=](Painter &p, int x, int y, int outerWidth, int size) mutable {
userpic->paintCircle(p, x, y, outerWidth, size);
using PeerType = Data::CreditsHistoryEntry::PeerType;
if (entry.peerType == PeerType::PremiumBot) {
return;
}
const auto rect = QRect(x, y, size, size);
((entry.peerType == PeerType::AppStore)
? st::sessionIconiPhone
Expand Down Expand Up @@ -446,6 +457,8 @@ Fn<PaintRoundImageCallback(Fn<void()>)> PaintPreviewCallback(
TextWithEntities GenerateEntryName(const Data::CreditsHistoryEntry &entry) {
return ((entry.peerType == Data::CreditsHistoryEntry::PeerType::Fragment)
? tr::lng_bot_username_description1_link
: (entry.peerType == Data::CreditsHistoryEntry::PeerType::PremiumBot)
? tr::lng_credits_box_history_entry_premium_bot
: (entry.peerType == Data::CreditsHistoryEntry::PeerType::Ads)
? tr::lng_credits_box_history_entry_ads
: tr::lng_credits_summary_history_entry_inner_in)(
Expand Down

0 comments on commit 4f7a124

Please sign in to comment.