diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 840a05eb1..fcf51bb0b 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2406,6 +2406,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_credits_box_history_entry_fragment" = "Fragment"; "lng_credits_box_history_entry_anonymous" = "Unknown User"; "lng_credits_box_history_entry_gift_name" = "Received Gift"; +"lng_credits_box_history_entry_giveaway_name" = "Received Prize"; "lng_credits_box_history_entry_gift_sent" = "Sent Gift"; "lng_credits_box_history_entry_gift_out_about" = "With Stars, **{user}** will be able to unlock content and services on Telegram.\n{link}"; "lng_credits_box_history_entry_gift_in_about" = "Use Stars to unlock content and services on Telegram. {link}"; diff --git a/Telegram/SourceFiles/api/api_credits.cpp b/Telegram/SourceFiles/api/api_credits.cpp index f969247bb..f26a9380b 100644 --- a/Telegram/SourceFiles/api/api_credits.cpp +++ b/Telegram/SourceFiles/api/api_credits.cpp @@ -79,6 +79,8 @@ constexpr auto kTransactionsLimit = 100; .credits = tl.data().vstars().v, .bareMsgId = uint64(tl.data().vmsg_id().value_or_empty()), .barePeerId = barePeerId, + .bareGiveawayMsgId = uint64( + tl.data().vgiveaway_post_id().value_or_empty()), .peerType = tl.data().vpeer().match([](const HistoryPeerTL &) { return Data::CreditsHistoryEntry::PeerType::Peer; }, [](const MTPDstarsTransactionPeerPlayMarket &) { diff --git a/Telegram/SourceFiles/boxes/gift_premium_box.cpp b/Telegram/SourceFiles/boxes/gift_premium_box.cpp index 321af87fe..3fd6bf687 100644 --- a/Telegram/SourceFiles/boxes/gift_premium_box.cpp +++ b/Telegram/SourceFiles/boxes/gift_premium_box.cpp @@ -1651,6 +1651,21 @@ void AddCreditsHistoryEntryTable( st::giveawayGiftCodeTable), st::giveawayGiftCodeTableMargin); const auto peerId = PeerId(entry.barePeerId); + const auto createMessageLink = [&](uint64 messageId) { + if (const auto msgId = MsgId(peerId ? messageId : 0)) { + const auto session = &controller->session(); + const auto peer = session->data().peer(peerId); + if (const auto channel = peer->asBroadcast()) { + const auto username = channel->username(); + const auto base = username.isEmpty() + ? u"c/%1"_q.arg(peerToChannel(channel->id).bare) + : username; + const auto query = base + '/' + QString::number(msgId.bare); + return session->createInternalLink(query); + } + } + return QString(); + }; if (peerId) { auto text = entry.in ? tr::lng_credits_box_history_entry_peer_in() @@ -1661,12 +1676,7 @@ void AddCreditsHistoryEntryTable( const auto session = &controller->session(); const auto peer = session->data().peer(peerId); if (const auto channel = peer->asBroadcast()) { - const auto username = channel->username(); - const auto base = username.isEmpty() - ? u"c/%1"_q.arg(peerToChannel(channel->id).bare) - : username; - const auto query = base + '/' + QString::number(msgId.bare); - const auto link = session->createInternalLink(query); + const auto link = createMessageLink(entry.bareMsgId); auto label = object_ptr( table, rpl::single(Ui::Text::Link(link)), @@ -1717,6 +1727,27 @@ void AddCreditsHistoryEntryTable( tr::lng_credits_box_history_entry_via_premium_bot( Ui::Text::RichLangValue)); } + if (entry.bareGiveawayMsgId && entry.credits) { + AddTableRow( + table, + tr::lng_gift_link_label_gift(), + tr::lng_gift_stars_title( + lt_count, + rpl::single(float64(entry.credits)), + Ui::Text::RichLangValue)); + } + { + const auto link = createMessageLink(entry.bareGiveawayMsgId); + if (!link.isEmpty()) { + AddTableRow( + table, + tr::lng_gift_link_label_reason(), + tr::lng_gift_link_reason_giveaway( + ) | rpl::map([link](const QString &text) { + return Ui::Text::Link(text, link); + })); + } + } if (!entry.id.isEmpty()) { constexpr auto kOneLineCount = 18; const auto oneLine = entry.id.length() <= kOneLineCount; diff --git a/Telegram/SourceFiles/data/data_credits.h b/Telegram/SourceFiles/data/data_credits.h index 0e0058cd8..8882fc43c 100644 --- a/Telegram/SourceFiles/data/data_credits.h +++ b/Telegram/SourceFiles/data/data_credits.h @@ -57,6 +57,7 @@ struct CreditsHistoryEntry final { uint64 credits = 0; uint64 bareMsgId = 0; uint64 barePeerId = 0; + uint64 bareGiveawayMsgId = 0; PeerType peerType; QDateTime subscriptionUntil; QDateTime successDate; diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp b/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp index 050ff4a97..86ec6c320 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp +++ b/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_credits.h" #include "api/api_statistics.h" #include "boxes/peer_list_controllers.h" +#include "chat_helpers/stickers_gift_box_pack.h" #include "core/ui_integration.h" // Core::MarkedTextContext. #include "data/data_channel.h" #include "data/data_credits.h" @@ -810,7 +811,7 @@ void CreditsRow::init() { const auto name = !isSpecial ? PeerListRow::generateName() : Ui::GenerateEntryName(_entry).text; - _name = _entry.reaction + _name = (_entry.reaction || _entry.bareGiveawayMsgId) ? Ui::GenerateEntryName(_entry).text : _entry.title.isEmpty() ? name @@ -1041,7 +1042,13 @@ void CreditsController::applySlice(const Data::CreditsStatusSlice &slice) { return std::make_unique(descriptor); } }; + + auto giftPacksRequested = false; for (const auto &item : slice.list) { + if (item.bareGiveawayMsgId && !giftPacksRequested) { + giftPacksRequested = true; + session().giftBoxStickersPacks().load(); + } delegate()->peerListAppendRow(create(item, {})); } for (const auto &item : slice.subscriptions) { diff --git a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp index 00950b6c9..19519429b 100644 --- a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp +++ b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp @@ -515,7 +515,10 @@ void ReceiptCreditsBox( const auto &stUser = st::boostReplaceUserpic; const auto session = &controller->session(); - const auto peer = (s.barePeerId) + const auto isPrize = e.bareGiveawayMsgId > 0; + const auto peer = isPrize + ? nullptr + : (s.barePeerId) ? session->data().peer(PeerId(s.barePeerId)).get() : (e.peerType == Type::PremiumBot) ? nullptr @@ -531,7 +534,7 @@ void ReceiptCreditsBox( content->add(object_ptr>( content, object_ptr(content, peer, stUser))); - } else if (e.gift) { + } else if (e.gift || isPrize) { struct State final { DocumentData *sticker = nullptr; std::shared_ptr media; @@ -612,6 +615,8 @@ void ReceiptCreditsBox( box, rpl::single(!s.until.isNull() ? tr::lng_credits_box_subscription_title(tr::now) + : isPrize + ? tr::lng_credits_box_history_entry_giveaway_name(tr::now) : !e.subscriptionUntil.isNull() ? tr::lng_credits_box_history_entry_subscription(tr::now) : !e.title.isEmpty() @@ -745,7 +750,7 @@ void ReceiptCreditsBox( rpl::single(e.description), st::creditsBoxAbout))); } - if (e.gift) { + if (e.gift || isPrize) { Ui::AddSkip(content); const auto arrow = Ui::Text::SingleCustomEmoji( session->data().customEmojiManager().registerInternalEmoji( diff --git a/Telegram/SourceFiles/ui/effects/credits_graphics.cpp b/Telegram/SourceFiles/ui/effects/credits_graphics.cpp index 7deb7e44f..16dc2ba77 100644 --- a/Telegram/SourceFiles/ui/effects/credits_graphics.cpp +++ b/Telegram/SourceFiles/ui/effects/credits_graphics.cpp @@ -457,6 +457,8 @@ Fn)> PaintPreviewCallback( TextWithEntities GenerateEntryName(const Data::CreditsHistoryEntry &entry) { return (entry.reaction ? tr::lng_credits_box_history_entry_reaction_name + : entry.bareGiveawayMsgId + ? tr::lng_credits_box_history_entry_giveaway_name : entry.gift ? tr::lng_credits_box_history_entry_gift_name : (entry.peerType == Data::CreditsHistoryEntry::PeerType::Fragment)