Skip to content

Commit

Permalink
Version 5.6.1: Support sold out gifts better.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Oct 7, 2024
1 parent cc22655 commit dd4fbc2
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 10 deletions.
5 changes: 5 additions & 0 deletions Telegram/Resources/langs/lang.strings
Original file line number Diff line number Diff line change
Expand Up @@ -2486,6 +2486,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_credits_small_balance_about" = "Buy **Stars** and use them on **{bot}** and other miniapps.";
"lng_credits_small_balance_reaction" = "Buy **Stars** and send them to {channel} to support their posts.";
"lng_credits_small_balance_subscribe" = "Buy **Stars** and subscribe to **{channel}** and other channels.";
"lng_credits_small_balance_star_gift" = "Buy **Stars** to send gifts to {user} and other contacts.";
"lng_credits_small_balance_fallback" = "Buy **Stars** to unlock content and services on Telegram.";
"lng_credits_purchase_blocked" = "Sorry, you can't purchase this item with Telegram Stars.";
"lng_credits_enough" = "You have enough stars at the moment. {link}";
Expand Down Expand Up @@ -3014,6 +3015,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_gift_stars_about" = "Give {name} gifts that can be kept on your profile or converted to Stars. {link}";
"lng_gift_stars_link" = "What are Stars >";
"lng_gift_stars_limited" = "limited";
"lng_gift_stars_sold_out" = "sold out";
"lng_gift_stars_tabs_all" = "All Gifts";
"lng_gift_stars_tabs_limited" = "Limited";
"lng_gift_send_title" = "Send a Gift";
Expand Down Expand Up @@ -3047,6 +3049,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_gift_display_done_hide" = "The gift is now hidden from your profile page.";
"lng_gift_got_stars#one" = "You got **{count} Star** for this gift.";
"lng_gift_got_stars#other" = "You got **{count} Stars** for this gift.";
"lng_gift_sold_out_title" = "Sold Out!";
"lng_gift_sold_out_text#one" = "All {count} gift was already sold.";
"lng_gift_sold_out_text#other" = "All {count} gifts were already sold.";

"lng_accounts_limit_title" = "Limit Reached";
"lng_accounts_limit1#one" = "You have reached the limit of **{count}** connected account.";
Expand Down
10 changes: 10 additions & 0 deletions Telegram/SourceFiles/boxes/star_gift_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ void PreviewWrap::paintEvent(QPaintEvent *e) {
.convertStars = gift.convertStars,
.document = gift.document,
.limitedCount = gift.limitedCount,
.limitedLeft = gift.limitedLeft,
});
}
auto &map = Map[session];
Expand Down Expand Up @@ -1081,6 +1082,7 @@ void SendGiftBox(
}
};
button->setClickedCallback([=] {
const auto star = std::get_if<GiftTypeStars>(&descriptor);
if (v::is<GiftTypePremium>(descriptor)) {
if (state->sending) {
return;
Expand All @@ -1093,6 +1095,14 @@ void SendGiftBox(
api,
GiftDetails{ descriptor },
premiumSent);
} else if (star && star->limitedCount && !star->limitedLeft) {
window->showToast({
.title = tr::lng_gift_sold_out_title(tr::now),
.text = tr::lng_gift_sold_out_text(
tr::now,
lt_count_decimal,
star->limitedCount),
});
} else {
window->show(
Box(SendGiftBox, window, peer, api, descriptor));
Expand Down
11 changes: 8 additions & 3 deletions Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,20 @@ void GiftButton::paintEvent(QPaintEvent *e) {
p.setFont(font);
const auto text = v::match(_descriptor, [&](GiftTypePremium data) {
if (data.discountPercent > 0) {
p.setBrush(st::attentionBoxButton.textFg);
p.setBrush(st::attentionButtonFg);
const auto kMinus = QChar(0x2212);
return kMinus + QString::number(data.discountPercent) + '%';
}
return QString();
}, [&](const GiftTypeStars &data) {
if (const auto count = data.limitedCount) {
p.setBrush(st::windowActiveTextFg);
return !data.userpic
const auto soldOut = !data.userpic && !data.limitedLeft;
p.setBrush(soldOut
? st::attentionButtonFg
: st::windowActiveTextFg);
return soldOut
? tr::lng_gift_stars_sold_out(tr::now)
: !data.userpic
? tr::lng_gift_stars_limited(tr::now)
: (count == 1)
? tr::lng_gift_limited_of_one(tr::now)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct GiftTypeStars {
DocumentData *document = nullptr;
PeerData *from = nullptr;
int limitedCount = 0;
int limitedLeft = 0;
bool userpic = false;
bool hidden = false;
bool mine = false;
Expand Down
13 changes: 8 additions & 5 deletions Telegram/SourceFiles/payments/payments_non_panel_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,14 @@ void ProcessCreditsPayment(
});
}, box->lifetime());
};
Settings::MaybeRequestBalanceIncrease(
show,
form->invoice.credits,
Settings::SmallBalanceBot{ .botId = form->botId },
done);
using namespace Settings;
const auto starGift = std::get_if<InvoiceStarGift>(&form->id.value);
auto source = !starGift
? SmallBalanceSource(SmallBalanceBot{ .botId = form->botId })
: SmallBalanceSource(SmallBalanceStarGift{
.userId = peerToUser(starGift->user->id)
});
MaybeRequestBalanceIncrease(show, form->invoice.credits, source, done);
}

void ProcessCreditsReceipt(
Expand Down
14 changes: 13 additions & 1 deletion Telegram/SourceFiles/settings/settings_credits_graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1555,13 +1555,17 @@ void SmallBalanceBox(

const auto owner = &show->session().data();
const auto name = v::match(source, [&](SmallBalanceBot value) {
return owner->peer(peerFromUser(value.botId))->name();
return value.botId
? owner->peer(peerFromUser(value.botId))->name()
: QString();
}, [&](SmallBalanceReaction value) {
return owner->peer(peerFromChannel(value.channelId))->name();
}, [](SmallBalanceSubscription value) {
return value.name;
}, [](SmallBalanceDeepLink value) {
return QString();
}, [&](SmallBalanceStarGift value) {
return owner->peer(peerFromUser(value.userId))->shortName();
});

auto needed = show->session().credits().balanceValue(
Expand Down Expand Up @@ -1591,6 +1595,14 @@ void SmallBalanceBox(
: v::is<SmallBalanceDeepLink>(source)
? DeepLinkBalanceAbout(
v::get<SmallBalanceDeepLink>(source).purpose)
: v::is<SmallBalanceStarGift>(source)
? tr::lng_credits_small_balance_star_gift(
lt_user,
rpl::single(Ui::Text::Bold(name)),
Ui::Text::RichLangValue)
: name.isEmpty()
? tr::lng_credits_small_balance_fallback(
Ui::Text::RichLangValue)
: tr::lng_credits_small_balance_about(
lt_bot,
rpl::single(TextWithEntities{ name }),
Expand Down
6 changes: 5 additions & 1 deletion Telegram/SourceFiles/settings/settings_credits_graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,15 @@ struct SmallBalanceSubscription {
struct SmallBalanceDeepLink {
QString purpose;
};
struct SmallBalanceStarGift {
UserId userId = 0;
};
struct SmallBalanceSource : std::variant<
SmallBalanceBot,
SmallBalanceReaction,
SmallBalanceSubscription,
SmallBalanceDeepLink> {
SmallBalanceDeepLink,
SmallBalanceStarGift> {
using variant::variant;
};

Expand Down

0 comments on commit dd4fbc2

Please sign in to comment.