From bce310d5c84ea17283b81d014b8a6876a78fdc61 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 17 Dec 2023 12:06:42 +0300 Subject: [PATCH] Added complex description to top of gift box from settings. --- Telegram/Resources/langs/lang.strings | 7 ++ .../SourceFiles/boxes/gift_premium_box.cpp | 83 ++++++++++++++++++- 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 1fb6041dc9..d5a07ed7d4 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2061,6 +2061,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_premium_gift_per" = "{cost} / month"; "lng_premium_gift_terms" = "You can review the list of features and terms of use for Telegram Premium {link}."; "lng_premium_gift_terms_link" = "here"; +"lng_premium_gifts_about_user1" = "Give **{user}** access to exclusive features."; +"lng_premium_gifts_about_user2" = "Give **{user}** and **{second_user}** access to exclusive features."; +"lng_premium_gifts_about_user3" = "Give **{user}**, **{second_user}** and **{name}** access to exclusive features."; +"lng_premium_gifts_about_user_more#one" = "Give **{user}**, **{second_user}**, **{name}** and **{count}** more friend access to exclusive features."; +"lng_premium_gifts_about_user_more#other" = "Give **{user}**, **{second_user}**, **{name}** and **{count}** more friends access to exclusive features."; +"lng_premium_gifts_about_reward#one" = "You will receive {emoji}**{count}** boost."; +"lng_premium_gifts_about_reward#other" = "You will receive {emoji}**{count}** boosts."; "lng_boost_channel_button" = "Boost Channel"; "lng_boost_again_button" = "Boost Again"; diff --git a/Telegram/SourceFiles/boxes/gift_premium_box.cpp b/Telegram/SourceFiles/boxes/gift_premium_box.cpp index f950b939a1..dd147bf998 100644 --- a/Telegram/SourceFiles/boxes/gift_premium_box.cpp +++ b/Telegram/SourceFiles/boxes/gift_premium_box.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/weak_ptr.h" #include "boxes/peer_list_controllers.h" // ContactsBoxController. #include "boxes/peers/prepare_short_info_box.h" +#include "boxes/peers/replace_boost_box.h" // BoostsForGift. #include "data/data_boosts.h" #include "data/data_changes.h" #include "data/data_channel.h" @@ -56,6 +57,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace { constexpr auto kDiscountDivider = 5.; +constexpr auto kUserpicsMax = size_t(3); using GiftOption = Data::SubscriptionOption; using GiftOptions = Data::SubscriptionOptions; @@ -76,6 +78,65 @@ GiftOptions GiftOptionFromTL(const MTPDuserFull &data) { return result; } +[[nodiscard]] rpl::producer ComplexAboutLabel( + const std::vector> &users) { + Expects(!users.empty()); + + const auto session = &users.front()->session(); + const auto count = users.size(); + const auto nameValue = [&](not_null user) { + return session->changes().peerFlagsValue( + user, + Data::PeerUpdate::Flag::Name + ) | rpl::map([=] { return TextWithEntities{ user->firstName }; }); + }; + const auto addReward = [=](TextWithEntities text) { + text.append('\n'); + text.append('\n'); + text.append(tr::lng_premium_gifts_about_reward( + tr::now, + lt_count, + count * BoostsForGift(session), + lt_emoji, + TextWithEntities(), + Ui::Text::RichLangValue)); + return text; + }; + if (count == 1) { + return tr::lng_premium_gifts_about_user1( + lt_user, + nameValue(users.front()), + Ui::Text::RichLangValue) | rpl::map(addReward); + } else if (count == 2) { + return tr::lng_premium_gifts_about_user2( + lt_user, + nameValue(users.front()), + lt_second_user, + nameValue(users[1]), + Ui::Text::RichLangValue) | rpl::map(addReward); + } else if (count == 3) { + return tr::lng_premium_gifts_about_user3( + lt_user, + nameValue(users.front()), + lt_second_user, + nameValue(users[1]), + lt_name, + nameValue(users[2]), + Ui::Text::RichLangValue) | rpl::map(addReward); + } else { + return tr::lng_premium_gifts_about_user_more( + lt_count, + rpl::single(count - kUserpicsMax) | tr::to_count(), + lt_user, + nameValue(users.front()), + lt_second_user, + nameValue(users[1]), + lt_name, + nameValue(users[2]), + Ui::Text::RichLangValue) | rpl::map(addReward); + } +} + [[nodiscard]] not_null CircleBadge( not_null parent, const QString &text) { @@ -348,7 +409,6 @@ void GiftsBox( top, true); - constexpr auto kUserpicsMax = size_t(3); const auto maxWithUserpic = std::min(users.size(), kUserpicsMax); const auto userpics = UserpicsContainer( top, @@ -397,6 +457,27 @@ void GiftsBox( // Header. const auto &padding = st::premiumGiftAboutPadding; const auto available = boxWidth - padding.left() - padding.right(); + const auto &stTitle = st::premiumPreviewAboutTitle; + auto titleLabel = object_ptr( + box, + tr::lng_premium_gift_title(), + stTitle); + titleLabel->resizeToWidth(available); + box->addRow( + object_ptr>( + box, + std::move(titleLabel)), + st::premiumGiftTitlePadding); + + auto textLabel = object_ptr( + box, + ComplexAboutLabel(users), + st::premiumPreviewAbout); + textLabel->setTextColorOverride(stTitle.textFg->c); + textLabel->resizeToWidth(available); + box->addRow( + object_ptr>(box, std::move(textLabel)), + padding); // List. const auto options = api->options(users.size());