From 233f6ed13bcad57413be2fc89e16b3e40afb1e20 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 20 Nov 2025 14:13:43 +0400 Subject: [PATCH] Improve bid information display. --- Telegram/Resources/langs/lang.strings | 2 + .../boxes/star_gift_auction_box.cpp | 30 ++++-- .../view/media/history_view_premium_gift.cpp | 98 ++++++++----------- Telegram/SourceFiles/lang/lang_text_entity.h | 3 + Telegram/SourceFiles/ui/effects/credits.style | 6 ++ 5 files changed, 76 insertions(+), 63 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 6b15cbe9b4..4fd2ddbba2 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -4030,6 +4030,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_auction_menu_copy_link" = "Copy Link"; "lng_auction_menu_share" = "Share"; "lng_auction_bid_title" = "Place a Bid"; +"lng_auction_bid_subtitle#one" = "Top {count} bidder will win"; +"lng_auction_bid_subtitle#other" = "Top {count} bidders will win"; "lng_auction_bid_your" = "your bid"; "lng_auction_bid_custom" = "click to bid more"; "lng_auction_bid_threshold#one" = "TOP {count}"; diff --git a/Telegram/SourceFiles/boxes/star_gift_auction_box.cpp b/Telegram/SourceFiles/boxes/star_gift_auction_box.cpp index 271ab4c6ea..5a15525d34 100644 --- a/Telegram/SourceFiles/boxes/star_gift_auction_box.cpp +++ b/Telegram/SourceFiles/boxes/star_gift_auction_box.cpp @@ -65,6 +65,7 @@ namespace { constexpr auto kAuctionAboutShownPref = "gift_auction_about_shown"_cs; constexpr auto kBidPlacedToastDuration = 5 * crl::time(1000); constexpr auto kMaxShownBid = 30'000; +constexpr auto kShowTopPlaces = 3; enum class BidType { Setting, @@ -405,16 +406,16 @@ void AddBidPlaces( const auto &levels = value.bidLevels; auto top = std::vector(); - top.reserve(3); + top.reserve(kShowTopPlaces); const auto pushTop = [&](auto i) { const auto index = int(i - begin(levels)); - if (top.size() < 3 - && index < value.topBidders.size() - && !value.topBidders[index]->isSelf()) { + if (top.size() >= kShowTopPlaces + || index >= value.topBidders.size()) { + return false; + } else if (!value.topBidders[index]->isSelf()) { top.push_back({ value.topBidders[index], int(i->amount) }); - return true; } - return false; + return true; }; const auto setting = (chosen > my); @@ -474,7 +475,7 @@ void AddBidPlaces( box->verticalLayout(), tr::lng_auction_bid_winners_title(), { 0, st::paidReactTitleSkip / 2, 0, 0 }); - for (auto i = 0; i != 3; ++i) { + for (auto i = 0; i != kShowTopPlaces; ++i) { auto icon = QString::fromUtf8("\xf0\x9f\xa5\x87"); icon.back().unicode() += i; @@ -676,7 +677,20 @@ void AuctionBidBox(not_null box, AuctionBidBoxArgs &&args) { box, tr::lng_auction_bid_title(), st::boostCenteredTitle), - st::boxRowPadding + QMargins(0, skip, 0, 0), + st::boxRowPadding + QMargins(0, skip / 2, 0, 0), + style::al_top); + + auto subtitle = tr::lng_auction_bid_subtitle( + lt_count, + state->value.value( + ) | rpl::map([=](const Data::GiftAuctionState &state) { + return state.gift->auctionGiftsPerRound * 1.; + })); + box->addRow( + object_ptr( + box, + std::move(subtitle), + st::auctionCenteredSubtitle), style::al_top); const auto setMinimal = [=] { diff --git a/Telegram/SourceFiles/history/view/media/history_view_premium_gift.cpp b/Telegram/SourceFiles/history/view/media/history_view_premium_gift.cpp index fca6153188..e73bc4b55e 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_premium_gift.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_premium_gift.cpp @@ -69,81 +69,79 @@ QSize PremiumGift::size() { } TextWithEntities PremiumGift::title() { - using namespace Ui::Text; if (tonGift()) { return tr::lng_gift_ton_amount( tr::now, lt_count_decimal, CreditsAmount(0, _data.count, CreditsType::Ton).value(), - Ui::Text::WithEntities); + tr::marked); } else if (starGift()) { const auto peer = _parent->history()->peer; const auto to = _data.auctionTo ? _data.auctionTo : peer.get(); return peer->isSelf() - ? tr::lng_action_gift_self_subtitle(tr::now, WithEntities) + ? tr::lng_action_gift_self_subtitle(tr::now, tr::marked) : (peer->isServiceUser() && _data.channelFrom) ? tr::lng_action_gift_got_subtitle( tr::now, lt_user, - WithEntities({}) - .append(SingleCustomEmoji( + tr::marked() + .append(Ui::Text::SingleCustomEmoji( peer->owner().customEmojiManager( - ).peerUserpicEmojiData(_data.channelFrom))) + ).peerUserpicEmojiData(_data.channelFrom))) .append(' ') .append(_data.channelFrom->shortName()), - WithEntities) + tr::marked) : (!_data.auctionTo && peer->isServiceUser()) - ? tr::lng_gift_link_label_gift(tr::now, WithEntities) + ? tr::lng_gift_link_label_gift(tr::now, tr::marked) : (outgoingGift() ? tr::lng_action_gift_sent_subtitle : tr::lng_action_gift_got_subtitle)( tr::now, lt_user, - WithEntities({}) - .append(SingleCustomEmoji( + tr::marked() + .append(Ui::Text::SingleCustomEmoji( to->owner().customEmojiManager( - ).peerUserpicEmojiData(to))) + ).peerUserpicEmojiData(to))) .append(' ') .append(to->shortName()), - WithEntities); + tr::marked); } else if (creditsPrize()) { - return tr::lng_prize_title(tr::now, WithEntities); - } else if (const auto c = credits()) { - return tr::lng_gift_stars_title(tr::now, lt_count, c, WithEntities); + return tr::lng_prize_title(tr::now, tr::marked); + } else if (const auto stars = credits()) { + return tr::lng_gift_stars_title(tr::now, lt_count_decimal, stars, tr::marked); } return gift() ? tr::lng_action_gift_premium_months( tr::now, lt_count, premiumMonths(), - WithEntities) + tr::marked) : _data.unclaimed - ? tr::lng_prize_unclaimed_title(tr::now, WithEntities) - : tr::lng_prize_title(tr::now, WithEntities); + ? tr::lng_prize_unclaimed_title(tr::now, tr::marked) + : tr::lng_prize_title(tr::now, tr::marked); } TextWithEntities PremiumGift::author() { - using namespace Ui::Text; if (!_data.stargiftReleasedBy) { return {}; } return tr::lng_gift_released_by( tr::now, lt_name, - Ui::Text::Link('@' + _data.stargiftReleasedBy->username()), - Ui::Text::WithEntities); + tr::link('@' + _data.stargiftReleasedBy->username()), + tr::marked); } TextWithEntities PremiumGift::subtitle() { if (tonGift()) { - return tr::lng_action_gift_got_ton(tr::now, Ui::Text::WithEntities); + return tr::lng_action_gift_got_ton(tr::now, tr::marked); } else if (starGift()) { const auto toChannel = _data.channel && _parent->history()->peer->isServiceUser(); return !_data.message.empty() ? _data.message : _data.refunded - ? tr::lng_action_gift_refunded(tr::now, Ui::Text::RichLangValue) + ? tr::lng_action_gift_refunded(tr::now, tr::rich) : outgoingGift() ? (_data.auctionTo ? tr::lng_action_gift_self_auction( @@ -151,7 +149,7 @@ TextWithEntities PremiumGift::subtitle() { lt_cost, tr::lng_action_gift_for_stars( tr::now, - lt_count, + lt_count_decimal, _data.starsBid, tr::marked), tr::rich) @@ -159,32 +157,26 @@ TextWithEntities PremiumGift::subtitle() { ? tr::lng_action_gift_sent_upgradable( tr::now, lt_user, - Ui::Text::Bold(_parent->history()->peer->shortName()), - Ui::Text::RichLangValue) + tr::bold(_parent->history()->peer->shortName()), + tr::rich) : tr::lng_action_gift_sent_text( tr::now, - lt_count, + lt_count_decimal, _data.starsConverted, lt_user, - Ui::Text::Bold(_parent->history()->peer->shortName()), - Ui::Text::RichLangValue)) + tr::bold(_parent->history()->peer->shortName()), + tr::rich)) : _data.starsUpgradedBySender - ? tr::lng_action_gift_got_upgradable_text( - tr::now, - Ui::Text::RichLangValue) + ? tr::lng_action_gift_got_upgradable_text(tr::now, tr::rich) : (_data.starsToUpgrade && !_data.converted && _parent->history()->peer->isSelf()) - ? tr::lng_action_gift_self_about_unique( - tr::now, - Ui::Text::RichLangValue) + ? tr::lng_action_gift_self_about_unique(tr::now, tr::rich) : (_data.starsToUpgrade && !_data.converted && _parent->history()->peer->isServiceUser() && _data.channel) - ? tr::lng_action_gift_channel_about_unique( - tr::now, - Ui::Text::RichLangValue) + ? tr::lng_action_gift_channel_about_unique(tr::now, tr::rich) : (!_data.converted && !_data.starsConverted) ? (_data.saved ? (toChannel @@ -192,9 +184,7 @@ TextWithEntities PremiumGift::subtitle() { : tr::lng_action_gift_can_remove_text) : (toChannel ? tr::lng_action_gift_got_gift_channel - : tr::lng_action_gift_got_gift_text))( - tr::now, - Ui::Text::RichLangValue) + : tr::lng_action_gift_got_gift_text))(tr::now, tr::rich) : (_data.converted ? (toChannel ? tr::lng_gift_channel_got @@ -207,7 +197,7 @@ TextWithEntities PremiumGift::subtitle() { tr::now, lt_count, _data.starsConverted, - Ui::Text::RichLangValue); + tr::rich); } const auto isCreditsPrize = creditsPrize(); if (const auto count = credits(); count && !isCreditsPrize) { @@ -215,15 +205,13 @@ TextWithEntities PremiumGift::subtitle() { ? tr::lng_gift_stars_outgoing( tr::now, lt_user, - Ui::Text::Bold(_parent->history()->peer->shortName()), - Ui::Text::RichLangValue) - : tr::lng_gift_stars_incoming(tr::now, Ui::Text::WithEntities); + tr::bold(_parent->history()->peer->shortName()), + tr::rich) + : tr::lng_gift_stars_incoming(tr::now, tr::marked); } else if (gift()) { return !_data.message.empty() ? _data.message - : tr::lng_action_gift_premium_about( - tr::now, - Ui::Text::RichLangValue); + : tr::lng_action_gift_premium_about(tr::now, tr::rich); } const auto name = _data.channel ? _data.channel->name() : "channel"; auto result = (_data.unclaimed @@ -233,8 +221,8 @@ TextWithEntities PremiumGift::subtitle() { : tr::lng_prize_gift_about)( tr::now, lt_channel, - Ui::Text::Bold(name), - Ui::Text::RichLangValue); + tr::bold(name), + tr::rich); result.append("\n\n"); result.append(isCreditsPrize ? tr::lng_prize_credits( @@ -242,10 +230,10 @@ TextWithEntities PremiumGift::subtitle() { lt_amount, tr::lng_prize_credits_amount( tr::now, - lt_count, + lt_count_decimal, credits(), - Ui::Text::RichLangValue), - Ui::Text::RichLangValue) + tr::marked), + tr::rich) : (_data.unclaimed ? tr::lng_prize_unclaimed_duration : _data.viaGiveaway @@ -253,8 +241,8 @@ TextWithEntities PremiumGift::subtitle() { : tr::lng_prize_gift_duration)( tr::now, lt_duration, - Ui::Text::Bold(GiftDuration(premiumDays())), - Ui::Text::RichLangValue)); + tr::bold(GiftDuration(premiumDays())), + tr::rich)); return result; } diff --git a/Telegram/SourceFiles/lang/lang_text_entity.h b/Telegram/SourceFiles/lang/lang_text_entity.h index b8c249144e..8a0a14e462 100644 --- a/Telegram/SourceFiles/lang/lang_text_entity.h +++ b/Telegram/SourceFiles/lang/lang_text_entity.h @@ -38,6 +38,9 @@ namespace tr { namespace details { struct MarkedProjection { + [[nodiscard]] TextWithEntities operator()() const { + return {}; + } [[nodiscard]] TextWithEntities operator()(const QString &value) const { return TextWithEntities{ value }; } diff --git a/Telegram/SourceFiles/ui/effects/credits.style b/Telegram/SourceFiles/ui/effects/credits.style index 4d887a79fb..8b53e20740 100644 --- a/Telegram/SourceFiles/ui/effects/credits.style +++ b/Telegram/SourceFiles/ui/effects/credits.style @@ -446,6 +446,12 @@ auctionInfoSubtitleSkip: 8px; auctionInfoTableMargin: margins(0px, 12px, 0px, 12px); auctionAboutLogo: icon {{ "settings/large_auctions", windowFgActive }}; auctionAboutLogoPadding: margins(8px, 8px, 8px, 8px); +auctionCenteredSubtitle: FlatLabel(defaultFlatLabel) { + textFg: windowSubTextFg; + style: TextStyle(defaultTextStyle) { + font: font(10px); + } +} auctionBidPlace: FlatLabel(defaultFlatLabel) { style: semiboldTextStyle;