From 3cfbd6a93b747fdbfe0240f371122cf4eeff194e Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 15 Nov 2024 12:14:49 +0400 Subject: [PATCH] Support non-convertible star gifts from bots. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/api/api_credits.cpp | 3 +- Telegram/SourceFiles/api/api_premium.cpp | 4 +- Telegram/SourceFiles/api/api_premium.h | 4 +- .../SourceFiles/boxes/gift_premium_box.cpp | 14 +++++-- Telegram/SourceFiles/boxes/star_gift_box.cpp | 2 +- Telegram/SourceFiles/data/data_credits.h | 25 +++++++------ Telegram/SourceFiles/data/data_media_types.h | 2 +- Telegram/SourceFiles/history/history_item.cpp | 2 +- .../view/media/history_view_premium_gift.cpp | 4 +- .../info_statistics_list_controllers.cpp | 6 +-- .../settings/settings_credits_graphics.cpp | 37 +++++++++++++------ .../ui/effects/credits_graphics.cpp | 2 +- 13 files changed, 63 insertions(+), 43 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 905db2f92..2c124769b 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1879,6 +1879,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_action_gift_got_stars_text#one" = "Display this gift on your page or convert it to **{count}** Star."; "lng_action_gift_got_stars_text#other" = "Display this gift on your page or convert it to **{count}** Stars."; "lng_action_gift_got_gift_text" = "You can keep this gift on your page."; +"lng_action_gift_can_remove_text" = "You can remove this gift from your page."; "lng_action_gift_sent_subtitle" = "Gift for {user}"; "lng_action_gift_sent_text#one" = "{user} can display this gift on their page or convert it to {count} Star."; "lng_action_gift_sent_text#other" = "{user} can display this gift on their page or convert it to {count} Stars."; diff --git a/Telegram/SourceFiles/api/api_credits.cpp b/Telegram/SourceFiles/api/api_credits.cpp index 133a9326b..80e995219 100644 --- a/Telegram/SourceFiles/api/api_credits.cpp +++ b/Telegram/SourceFiles/api/api_credits.cpp @@ -117,11 +117,12 @@ constexpr auto kTransactionsLimit = 100; ? base::unixtime::parse(tl.data().vtransaction_date()->v) : QDateTime(), .successLink = qs(tl.data().vtransaction_url().value_or_empty()), - .convertStars = int(stargift + .starsConverted = int(stargift ? stargift->data().vconvert_stars().v : 0), .floodSkip = int(tl.data().vfloodskip_number().value_or(0)), .converted = stargift && incoming, + .stargift = stargift.has_value(), .reaction = tl.data().is_reaction(), .refunded = tl.data().is_refund(), .pending = tl.data().is_pending(), diff --git a/Telegram/SourceFiles/api/api_premium.cpp b/Telegram/SourceFiles/api/api_premium.cpp index 4328f04ce..91824922e 100644 --- a/Telegram/SourceFiles/api/api_premium.cpp +++ b/Telegram/SourceFiles/api/api_premium.cpp @@ -772,7 +772,7 @@ std::optional FromTL( return StarGift{ .id = uint64(data.vid().v), .stars = int64(data.vstars().v), - .convertStars = int64(data.vconvert_stars().v), + .starsConverted = int64(data.vconvert_stars().v), .document = document, .limitedLeft = remaining.value_or_empty(), .limitedCount = total.value_or_empty(), @@ -800,7 +800,7 @@ std::optional FromTL( data.vmessage()->data().ventities().v), } : TextWithEntities()), - .convertStars = int64(data.vconvert_stars().value_or_empty()), + .starsConverted = int64(data.vconvert_stars().value_or_empty()), .fromId = (data.vfrom_id() ? peerFromUser(data.vfrom_id()->v) : PeerId()), diff --git a/Telegram/SourceFiles/api/api_premium.h b/Telegram/SourceFiles/api/api_premium.h index f0567cbe0..ef08eb8fb 100644 --- a/Telegram/SourceFiles/api/api_premium.h +++ b/Telegram/SourceFiles/api/api_premium.h @@ -76,7 +76,7 @@ struct GiftOptionData { struct StarGift { uint64 id = 0; int64 stars = 0; - int64 convertStars = 0; + int64 starsConverted = 0; not_null document; int limitedLeft = 0; int limitedCount = 0; @@ -91,7 +91,7 @@ struct StarGift { struct UserStarGift { StarGift info; TextWithEntities message; - int64 convertStars = 0; + int64 starsConverted = 0; PeerId fromId = 0; MsgId messageId = 0; TimeId date = 0; diff --git a/Telegram/SourceFiles/boxes/gift_premium_box.cpp b/Telegram/SourceFiles/boxes/gift_premium_box.cpp index 915e2c48b..a3d385c72 100644 --- a/Telegram/SourceFiles/boxes/gift_premium_box.cpp +++ b/Telegram/SourceFiles/boxes/gift_premium_box.cpp @@ -266,7 +266,7 @@ object_ptr MakeStarGiftStarsValue( raw, tr::lng_gift_sell_small( lt_count_decimal, - rpl::single(entry.convertStars * 1.)), + rpl::single(entry.starsConverted * 1.)), st::starGiftSmallButton) : nullptr; if (convert) { @@ -1044,7 +1044,8 @@ void AddStarGiftTable( const auto peerId = PeerId(entry.barePeerId); const auto session = &controller->session(); if (peerId) { - const auto withSendButton = entry.in; + const auto user = session->data().peer(peerId)->asUser(); + const auto withSendButton = entry.in && user && !user->isBot(); AddTableRow( table, tr::lng_credits_box_history_entry_peer_in(), @@ -1144,12 +1145,17 @@ void AddCreditsHistoryEntryTable( st::giveawayGiftCodeTable), st::giveawayGiftCodeTableMargin); const auto peerId = PeerId(entry.barePeerId); + const auto actorId = PeerId(entry.bareActorId); const auto session = &controller->session(); - if (peerId) { + if (actorId || peerId) { auto text = entry.in ? tr::lng_credits_box_history_entry_peer_in() : tr::lng_credits_box_history_entry_peer(); - AddTableRow(table, std::move(text), controller, peerId); + AddTableRow( + table, + std::move(text), + controller, + actorId ? actorId : peerId); } if (const auto msgId = MsgId(peerId ? entry.bareMsgId : 0)) { const auto peer = session->data().peer(peerId); diff --git a/Telegram/SourceFiles/boxes/star_gift_box.cpp b/Telegram/SourceFiles/boxes/star_gift_box.cpp index 6c8203934..70fe207ab 100644 --- a/Telegram/SourceFiles/boxes/star_gift_box.cpp +++ b/Telegram/SourceFiles/boxes/star_gift_box.cpp @@ -216,7 +216,7 @@ auto GenerateGiftMedia( return tr::lng_action_gift_got_stars_text( tr::now, lt_count, - gift.info.convertStars, + gift.info.starsConverted, Ui::Text::RichLangValue); }); auto description = data.text.empty() diff --git a/Telegram/SourceFiles/data/data_credits.h b/Telegram/SourceFiles/data/data_credits.h index 28817376c..fe77aedc5 100644 --- a/Telegram/SourceFiles/data/data_credits.h +++ b/Telegram/SourceFiles/data/data_credits.h @@ -69,19 +69,20 @@ struct CreditsHistoryEntry final { QString successLink; int limitedCount = 0; int limitedLeft = 0; - int convertStars = 0; + int starsConverted = 0; int floodSkip = 0; - bool converted = false; - bool anonymous = false; - bool savedToProfile = false; - bool fromGiftsList = false; - bool soldOutInfo = false; - bool reaction = false; - bool refunded = false; - bool pending = false; - bool failed = false; - bool in = false; - bool gift = false; + bool converted : 1 = false; + bool anonymous : 1 = false; + bool stargift : 1 = false; + bool savedToProfile : 1 = false; + bool fromGiftsList : 1 = false; + bool soldOutInfo : 1 = false; + bool reaction : 1 = false; + bool refunded : 1 = false; + bool pending : 1 = false; + bool failed : 1 = false; + bool in : 1 = false; + bool gift : 1 = false; }; struct CreditsStatusSlice final { diff --git a/Telegram/SourceFiles/data/data_media_types.h b/Telegram/SourceFiles/data/data_media_types.h index 86dd6d594..57e684ee9 100644 --- a/Telegram/SourceFiles/data/data_media_types.h +++ b/Telegram/SourceFiles/data/data_media_types.h @@ -139,7 +139,7 @@ struct GiftCode { TextWithEntities message; ChannelData *channel = nullptr; MsgId giveawayMsgId = 0; - int convertStars = 0; + int starsConverted = 0; int limitedCount = 0; int limitedLeft = 0; int count = 0; diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 08b3187dc..c8f21a423 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -5530,7 +5530,7 @@ void HistoryItem::applyAction(const MTPMessageAction &action) { data.vmessage()->data().ventities().v), } : TextWithEntities()), - .convertStars = int(data.vconvert_stars().value_or_empty()), + .starsConverted = int(data.vconvert_stars().value_or_empty()), .limitedCount = gift.vavailability_total().value_or_empty(), .limitedLeft = gift.vavailability_remains().value_or_empty(), .count = int(gift.vstars().v), 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 12e9f1ffc..0a9aea114 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_premium_gift.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_premium_gift.cpp @@ -80,7 +80,7 @@ TextWithEntities PremiumGift::subtitle() { ? tr::lng_action_gift_sent_text( tr::now, lt_count, - _data.convertStars, + _data.starsConverted, lt_user, Ui::Text::Bold(_parent->history()->peer->shortName()), Ui::Text::RichLangValue) @@ -89,7 +89,7 @@ TextWithEntities PremiumGift::subtitle() { : tr::lng_action_gift_got_stars_text)( tr::now, lt_count, - _data.convertStars, + _data.starsConverted, Ui::Text::RichLangValue); } const auto isCreditsPrize = creditsPrize(); diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp b/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp index a14d9141d..abbd690c7 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp +++ b/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp @@ -822,9 +822,7 @@ void CreditsRow::init() { const auto name = !isSpecial ? PeerListRow::generateName() : Ui::GenerateEntryName(_entry).text; - _name = (_entry.reaction - || _entry.bareGiveawayMsgId - || _entry.convertStars) + _name = (_entry.reaction || _entry.stargift || _entry.bareGiveawayMsgId) ? Ui::GenerateEntryName(_entry).text : _entry.title.isEmpty() ? name @@ -876,7 +874,7 @@ void CreditsRow::init() { _context); } if (!_paintUserpicCallback) { - _paintUserpicCallback = _entry.convertStars + _paintUserpicCallback = _entry.stargift ? Ui::GenerateGiftStickerUserpicCallback( _context.session, _entry.bareGiftStickerId, diff --git a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp index 32804af35..fc1b1d8e8 100644 --- a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp +++ b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp @@ -797,7 +797,7 @@ void ReceiptCreditsBox( const Data::SubscriptionEntry &s) { const auto item = controller->session().data().message( PeerId(e.barePeerId), MsgId(e.bareMsgId)); - const auto isStarGift = (e.convertStars > 0) || e.soldOutInfo; + const auto isStarGift = e.stargift || e.soldOutInfo; const auto creditsHistoryStarGift = isStarGift && !e.id.isEmpty(); const auto sentStarGift = creditsHistoryStarGift && !e.in; const auto convertedStarGift = creditsHistoryStarGift && e.converted; @@ -811,9 +811,13 @@ void ReceiptCreditsBox( + controller->session().appConfig().stargiftConvertPeriodMax(); const auto timeLeft = int64(convertLast) - int64(base::unixtime::now()); const auto timeExceeded = (timeLeft <= 0); - const auto forConvert = gotStarGift && !e.converted && starGiftSender; + const auto forConvert = gotStarGift + && e.starsConverted + && !e.converted + && starGiftSender; const auto canConvert = forConvert && !timeExceeded; const auto couldConvert = forConvert && timeExceeded; + const auto nonConvertible = (gotStarGift && !e.starsConverted); box->setStyle(st::giveawayGiftCodeBox); box->setNoContentMargin(true); @@ -1108,15 +1112,17 @@ void ReceiptCreditsBox( box, object_ptr( box, - (couldConvert - ? tr::lng_action_gift_got_gift_text( - Ui::Text::WithEntities) + ((couldConvert || nonConvertible) + ? (e.savedToProfile + ? tr::lng_action_gift_can_remove_text + : tr::lng_action_gift_got_gift_text)( + Ui::Text::WithEntities) : rpl::combine( (canConvert ? tr::lng_action_gift_got_stars_text : tr::lng_gift_got_stars)( lt_count, - rpl::single(e.convertStars * 1.), + rpl::single(e.starsConverted * 1.), Ui::Text::RichLangValue), tr::lng_paid_about_link() ) | rpl::map([]( @@ -1180,7 +1186,7 @@ void ReceiptCreditsBox( if (isStarGift && e.id.isEmpty()) { const auto convert = [=, weak = Ui::MakeWeak(box)] { - const auto stars = e.convertStars; + const auto stars = e.starsConverted; const auto days = canConvert ? ((timeLeft + 86399) / 86400) : 0; const auto name = starGiftSender->shortName(); ConfirmConvertStarGift(box->uiShow(), name, stars, days, [=] { @@ -1319,13 +1325,13 @@ void ReceiptCreditsBox( ? tr::lng_credits_subscription_off_button() : toCancel ? tr::lng_credits_subscription_on_button() - : (canConvert || couldConvert) + : (canConvert || couldConvert || nonConvertible) ? (e.savedToProfile ? tr::lng_gift_display_on_page_hide() : tr::lng_gift_display_on_page()) : tr::lng_box_ok())); const auto send = [=, weak = Ui::MakeWeak(box)] { - if (canConvert || couldConvert) { + if (canConvert || couldConvert || nonConvertible) { const auto save = !e.savedToProfile; const auto window = weakWindow.get(); const auto showSection = !e.fromGiftsList; @@ -1399,7 +1405,12 @@ void ReceiptCreditsBox( return; } state->confirmButtonBusy = true; - if ((toRenew || toCancel || canConvert || couldConvert) && peer) { + if (peer + && (toRenew + || toCancel + || canConvert + || couldConvert + || nonConvertible)) { send(); } else { box->closeBox(); @@ -1491,9 +1502,10 @@ void UserStarGiftBox( .peerType = Data::CreditsHistoryEntry::PeerType::Peer, .limitedCount = data.info.limitedCount, .limitedLeft = data.info.limitedLeft, - .convertStars = int(data.info.convertStars), + .starsConverted = int(data.info.starsConverted), .converted = false, .anonymous = data.anonymous, + .stargift = true, .savedToProfile = !data.hidden, .fromGiftsList = true, .in = data.mine, @@ -1521,9 +1533,10 @@ void StarGiftViewBox( .peerType = Data::CreditsHistoryEntry::PeerType::Peer, .limitedCount = data.limitedCount, .limitedLeft = data.limitedLeft, - .convertStars = data.convertStars, + .starsConverted = data.starsConverted, .converted = data.converted, .anonymous = data.anonymous, + .stargift = true, .savedToProfile = data.saved, .in = true, .gift = true, diff --git a/Telegram/SourceFiles/ui/effects/credits_graphics.cpp b/Telegram/SourceFiles/ui/effects/credits_graphics.cpp index 97b6a744c..76d899c76 100644 --- a/Telegram/SourceFiles/ui/effects/credits_graphics.cpp +++ b/Telegram/SourceFiles/ui/effects/credits_graphics.cpp @@ -553,7 +553,7 @@ TextWithEntities GenerateEntryName(const Data::CreditsHistoryEntry &entry) { ? tr::lng_credits_box_history_entry_giveaway_name : entry.converted ? tr::lng_credits_box_history_entry_gift_converted - : entry.convertStars + : entry.starsConverted ? tr::lng_credits_box_history_entry_gift_sent : entry.gift ? tr::lng_credits_box_history_entry_gift_name