Added support of credits giveaway to ReceiptCreditsBox.

This commit is contained in:
23rd 2024-08-28 21:23:46 +03:00 committed by John Preston
parent aea87bb5cb
commit 4520480604
7 changed files with 59 additions and 10 deletions

View file

@ -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}";

View file

@ -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 &) {

View file

@ -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<Ui::FlatLabel>(
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;

View file

@ -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;

View file

@ -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<CreditsRow>(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) {

View file

@ -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<Ui::CenterWrap<>>(
content,
object_ptr<Ui::UserpicButton>(content, peer, stUser)));
} else if (e.gift) {
} else if (e.gift || isPrize) {
struct State final {
DocumentData *sticker = nullptr;
std::shared_ptr<Data::DocumentMedia> 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(

View file

@ -457,6 +457,8 @@ Fn<PaintRoundImageCallback(Fn<void()>)> 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)