Version 5.6.1: Support sold out gifts better.

This commit is contained in:
John Preston 2024-10-07 14:47:08 +04:00
parent cc2265583f
commit dd4fbc256c
7 changed files with 50 additions and 10 deletions

View file

@ -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_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_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_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_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_purchase_blocked" = "Sorry, you can't purchase this item with Telegram Stars.";
"lng_credits_enough" = "You have enough stars at the moment. {link}"; "lng_credits_enough" = "You have enough stars at the moment. {link}";
@ -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_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_link" = "What are Stars >";
"lng_gift_stars_limited" = "limited"; "lng_gift_stars_limited" = "limited";
"lng_gift_stars_sold_out" = "sold out";
"lng_gift_stars_tabs_all" = "All Gifts"; "lng_gift_stars_tabs_all" = "All Gifts";
"lng_gift_stars_tabs_limited" = "Limited"; "lng_gift_stars_tabs_limited" = "Limited";
"lng_gift_send_title" = "Send a Gift"; "lng_gift_send_title" = "Send a Gift";
@ -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_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#one" = "You got **{count} Star** for this gift.";
"lng_gift_got_stars#other" = "You got **{count} Stars** 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_limit_title" = "Limit Reached";
"lng_accounts_limit1#one" = "You have reached the limit of **{count}** connected account."; "lng_accounts_limit1#one" = "You have reached the limit of **{count}** connected account.";

View file

@ -514,6 +514,7 @@ void PreviewWrap::paintEvent(QPaintEvent *e) {
.convertStars = gift.convertStars, .convertStars = gift.convertStars,
.document = gift.document, .document = gift.document,
.limitedCount = gift.limitedCount, .limitedCount = gift.limitedCount,
.limitedLeft = gift.limitedLeft,
}); });
} }
auto &map = Map[session]; auto &map = Map[session];
@ -1081,6 +1082,7 @@ void SendGiftBox(
} }
}; };
button->setClickedCallback([=] { button->setClickedCallback([=] {
const auto star = std::get_if<GiftTypeStars>(&descriptor);
if (v::is<GiftTypePremium>(descriptor)) { if (v::is<GiftTypePremium>(descriptor)) {
if (state->sending) { if (state->sending) {
return; return;
@ -1093,6 +1095,14 @@ void SendGiftBox(
api, api,
GiftDetails{ descriptor }, GiftDetails{ descriptor },
premiumSent); 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 { } else {
window->show( window->show(
Box(SendGiftBox, window, peer, api, descriptor)); Box(SendGiftBox, window, peer, api, descriptor));

View file

@ -253,15 +253,20 @@ void GiftButton::paintEvent(QPaintEvent *e) {
p.setFont(font); p.setFont(font);
const auto text = v::match(_descriptor, [&](GiftTypePremium data) { const auto text = v::match(_descriptor, [&](GiftTypePremium data) {
if (data.discountPercent > 0) { if (data.discountPercent > 0) {
p.setBrush(st::attentionBoxButton.textFg); p.setBrush(st::attentionButtonFg);
const auto kMinus = QChar(0x2212); const auto kMinus = QChar(0x2212);
return kMinus + QString::number(data.discountPercent) + '%'; return kMinus + QString::number(data.discountPercent) + '%';
} }
return QString(); return QString();
}, [&](const GiftTypeStars &data) { }, [&](const GiftTypeStars &data) {
if (const auto count = data.limitedCount) { if (const auto count = data.limitedCount) {
p.setBrush(st::windowActiveTextFg); const auto soldOut = !data.userpic && !data.limitedLeft;
return !data.userpic 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) ? tr::lng_gift_stars_limited(tr::now)
: (count == 1) : (count == 1)
? tr::lng_gift_limited_of_one(tr::now) ? tr::lng_gift_limited_of_one(tr::now)

View file

@ -48,6 +48,7 @@ struct GiftTypeStars {
DocumentData *document = nullptr; DocumentData *document = nullptr;
PeerData *from = nullptr; PeerData *from = nullptr;
int limitedCount = 0; int limitedCount = 0;
int limitedLeft = 0;
bool userpic = false; bool userpic = false;
bool hidden = false; bool hidden = false;
bool mine = false; bool mine = false;

View file

@ -93,11 +93,14 @@ void ProcessCreditsPayment(
}); });
}, box->lifetime()); }, box->lifetime());
}; };
Settings::MaybeRequestBalanceIncrease( using namespace Settings;
show, const auto starGift = std::get_if<InvoiceStarGift>(&form->id.value);
form->invoice.credits, auto source = !starGift
Settings::SmallBalanceBot{ .botId = form->botId }, ? SmallBalanceSource(SmallBalanceBot{ .botId = form->botId })
done); : SmallBalanceSource(SmallBalanceStarGift{
.userId = peerToUser(starGift->user->id)
});
MaybeRequestBalanceIncrease(show, form->invoice.credits, source, done);
} }
void ProcessCreditsReceipt( void ProcessCreditsReceipt(

View file

@ -1555,13 +1555,17 @@ void SmallBalanceBox(
const auto owner = &show->session().data(); const auto owner = &show->session().data();
const auto name = v::match(source, [&](SmallBalanceBot value) { 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) { }, [&](SmallBalanceReaction value) {
return owner->peer(peerFromChannel(value.channelId))->name(); return owner->peer(peerFromChannel(value.channelId))->name();
}, [](SmallBalanceSubscription value) { }, [](SmallBalanceSubscription value) {
return value.name; return value.name;
}, [](SmallBalanceDeepLink value) { }, [](SmallBalanceDeepLink value) {
return QString(); return QString();
}, [&](SmallBalanceStarGift value) {
return owner->peer(peerFromUser(value.userId))->shortName();
}); });
auto needed = show->session().credits().balanceValue( auto needed = show->session().credits().balanceValue(
@ -1591,6 +1595,14 @@ void SmallBalanceBox(
: v::is<SmallBalanceDeepLink>(source) : v::is<SmallBalanceDeepLink>(source)
? DeepLinkBalanceAbout( ? DeepLinkBalanceAbout(
v::get<SmallBalanceDeepLink>(source).purpose) 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( : tr::lng_credits_small_balance_about(
lt_bot, lt_bot,
rpl::single(TextWithEntities{ name }), rpl::single(TextWithEntities{ name }),

View file

@ -138,11 +138,15 @@ struct SmallBalanceSubscription {
struct SmallBalanceDeepLink { struct SmallBalanceDeepLink {
QString purpose; QString purpose;
}; };
struct SmallBalanceStarGift {
UserId userId = 0;
};
struct SmallBalanceSource : std::variant< struct SmallBalanceSource : std::variant<
SmallBalanceBot, SmallBalanceBot,
SmallBalanceReaction, SmallBalanceReaction,
SmallBalanceSubscription, SmallBalanceSubscription,
SmallBalanceDeepLink> { SmallBalanceDeepLink,
SmallBalanceStarGift> {
using variant::variant; using variant::variant;
}; };