mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added support of credits giveaway to ReceiptCreditsBox.
This commit is contained in:
parent
aea87bb5cb
commit
4520480604
7 changed files with 59 additions and 10 deletions
|
@ -2406,6 +2406,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_credits_box_history_entry_fragment" = "Fragment";
|
"lng_credits_box_history_entry_fragment" = "Fragment";
|
||||||
"lng_credits_box_history_entry_anonymous" = "Unknown User";
|
"lng_credits_box_history_entry_anonymous" = "Unknown User";
|
||||||
"lng_credits_box_history_entry_gift_name" = "Received Gift";
|
"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_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_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}";
|
"lng_credits_box_history_entry_gift_in_about" = "Use Stars to unlock content and services on Telegram. {link}";
|
||||||
|
|
|
@ -79,6 +79,8 @@ constexpr auto kTransactionsLimit = 100;
|
||||||
.credits = tl.data().vstars().v,
|
.credits = tl.data().vstars().v,
|
||||||
.bareMsgId = uint64(tl.data().vmsg_id().value_or_empty()),
|
.bareMsgId = uint64(tl.data().vmsg_id().value_or_empty()),
|
||||||
.barePeerId = barePeerId,
|
.barePeerId = barePeerId,
|
||||||
|
.bareGiveawayMsgId = uint64(
|
||||||
|
tl.data().vgiveaway_post_id().value_or_empty()),
|
||||||
.peerType = tl.data().vpeer().match([](const HistoryPeerTL &) {
|
.peerType = tl.data().vpeer().match([](const HistoryPeerTL &) {
|
||||||
return Data::CreditsHistoryEntry::PeerType::Peer;
|
return Data::CreditsHistoryEntry::PeerType::Peer;
|
||||||
}, [](const MTPDstarsTransactionPeerPlayMarket &) {
|
}, [](const MTPDstarsTransactionPeerPlayMarket &) {
|
||||||
|
|
|
@ -1651,6 +1651,21 @@ void AddCreditsHistoryEntryTable(
|
||||||
st::giveawayGiftCodeTable),
|
st::giveawayGiftCodeTable),
|
||||||
st::giveawayGiftCodeTableMargin);
|
st::giveawayGiftCodeTableMargin);
|
||||||
const auto peerId = PeerId(entry.barePeerId);
|
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) {
|
if (peerId) {
|
||||||
auto text = entry.in
|
auto text = entry.in
|
||||||
? tr::lng_credits_box_history_entry_peer_in()
|
? tr::lng_credits_box_history_entry_peer_in()
|
||||||
|
@ -1661,12 +1676,7 @@ void AddCreditsHistoryEntryTable(
|
||||||
const auto session = &controller->session();
|
const auto session = &controller->session();
|
||||||
const auto peer = session->data().peer(peerId);
|
const auto peer = session->data().peer(peerId);
|
||||||
if (const auto channel = peer->asBroadcast()) {
|
if (const auto channel = peer->asBroadcast()) {
|
||||||
const auto username = channel->username();
|
const auto link = createMessageLink(entry.bareMsgId);
|
||||||
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);
|
|
||||||
auto label = object_ptr<Ui::FlatLabel>(
|
auto label = object_ptr<Ui::FlatLabel>(
|
||||||
table,
|
table,
|
||||||
rpl::single(Ui::Text::Link(link)),
|
rpl::single(Ui::Text::Link(link)),
|
||||||
|
@ -1717,6 +1727,27 @@ void AddCreditsHistoryEntryTable(
|
||||||
tr::lng_credits_box_history_entry_via_premium_bot(
|
tr::lng_credits_box_history_entry_via_premium_bot(
|
||||||
Ui::Text::RichLangValue));
|
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()) {
|
if (!entry.id.isEmpty()) {
|
||||||
constexpr auto kOneLineCount = 18;
|
constexpr auto kOneLineCount = 18;
|
||||||
const auto oneLine = entry.id.length() <= kOneLineCount;
|
const auto oneLine = entry.id.length() <= kOneLineCount;
|
||||||
|
|
|
@ -57,6 +57,7 @@ struct CreditsHistoryEntry final {
|
||||||
uint64 credits = 0;
|
uint64 credits = 0;
|
||||||
uint64 bareMsgId = 0;
|
uint64 bareMsgId = 0;
|
||||||
uint64 barePeerId = 0;
|
uint64 barePeerId = 0;
|
||||||
|
uint64 bareGiveawayMsgId = 0;
|
||||||
PeerType peerType;
|
PeerType peerType;
|
||||||
QDateTime subscriptionUntil;
|
QDateTime subscriptionUntil;
|
||||||
QDateTime successDate;
|
QDateTime successDate;
|
||||||
|
|
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "api/api_credits.h"
|
#include "api/api_credits.h"
|
||||||
#include "api/api_statistics.h"
|
#include "api/api_statistics.h"
|
||||||
#include "boxes/peer_list_controllers.h"
|
#include "boxes/peer_list_controllers.h"
|
||||||
|
#include "chat_helpers/stickers_gift_box_pack.h"
|
||||||
#include "core/ui_integration.h" // Core::MarkedTextContext.
|
#include "core/ui_integration.h" // Core::MarkedTextContext.
|
||||||
#include "data/data_channel.h"
|
#include "data/data_channel.h"
|
||||||
#include "data/data_credits.h"
|
#include "data/data_credits.h"
|
||||||
|
@ -810,7 +811,7 @@ void CreditsRow::init() {
|
||||||
const auto name = !isSpecial
|
const auto name = !isSpecial
|
||||||
? PeerListRow::generateName()
|
? PeerListRow::generateName()
|
||||||
: Ui::GenerateEntryName(_entry).text;
|
: Ui::GenerateEntryName(_entry).text;
|
||||||
_name = _entry.reaction
|
_name = (_entry.reaction || _entry.bareGiveawayMsgId)
|
||||||
? Ui::GenerateEntryName(_entry).text
|
? Ui::GenerateEntryName(_entry).text
|
||||||
: _entry.title.isEmpty()
|
: _entry.title.isEmpty()
|
||||||
? name
|
? name
|
||||||
|
@ -1041,7 +1042,13 @@ void CreditsController::applySlice(const Data::CreditsStatusSlice &slice) {
|
||||||
return std::make_unique<CreditsRow>(descriptor);
|
return std::make_unique<CreditsRow>(descriptor);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto giftPacksRequested = false;
|
||||||
for (const auto &item : slice.list) {
|
for (const auto &item : slice.list) {
|
||||||
|
if (item.bareGiveawayMsgId && !giftPacksRequested) {
|
||||||
|
giftPacksRequested = true;
|
||||||
|
session().giftBoxStickersPacks().load();
|
||||||
|
}
|
||||||
delegate()->peerListAppendRow(create(item, {}));
|
delegate()->peerListAppendRow(create(item, {}));
|
||||||
}
|
}
|
||||||
for (const auto &item : slice.subscriptions) {
|
for (const auto &item : slice.subscriptions) {
|
||||||
|
|
|
@ -515,7 +515,10 @@ void ReceiptCreditsBox(
|
||||||
|
|
||||||
const auto &stUser = st::boostReplaceUserpic;
|
const auto &stUser = st::boostReplaceUserpic;
|
||||||
const auto session = &controller->session();
|
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()
|
? session->data().peer(PeerId(s.barePeerId)).get()
|
||||||
: (e.peerType == Type::PremiumBot)
|
: (e.peerType == Type::PremiumBot)
|
||||||
? nullptr
|
? nullptr
|
||||||
|
@ -531,7 +534,7 @@ void ReceiptCreditsBox(
|
||||||
content->add(object_ptr<Ui::CenterWrap<>>(
|
content->add(object_ptr<Ui::CenterWrap<>>(
|
||||||
content,
|
content,
|
||||||
object_ptr<Ui::UserpicButton>(content, peer, stUser)));
|
object_ptr<Ui::UserpicButton>(content, peer, stUser)));
|
||||||
} else if (e.gift) {
|
} else if (e.gift || isPrize) {
|
||||||
struct State final {
|
struct State final {
|
||||||
DocumentData *sticker = nullptr;
|
DocumentData *sticker = nullptr;
|
||||||
std::shared_ptr<Data::DocumentMedia> media;
|
std::shared_ptr<Data::DocumentMedia> media;
|
||||||
|
@ -612,6 +615,8 @@ void ReceiptCreditsBox(
|
||||||
box,
|
box,
|
||||||
rpl::single(!s.until.isNull()
|
rpl::single(!s.until.isNull()
|
||||||
? tr::lng_credits_box_subscription_title(tr::now)
|
? tr::lng_credits_box_subscription_title(tr::now)
|
||||||
|
: isPrize
|
||||||
|
? tr::lng_credits_box_history_entry_giveaway_name(tr::now)
|
||||||
: !e.subscriptionUntil.isNull()
|
: !e.subscriptionUntil.isNull()
|
||||||
? tr::lng_credits_box_history_entry_subscription(tr::now)
|
? tr::lng_credits_box_history_entry_subscription(tr::now)
|
||||||
: !e.title.isEmpty()
|
: !e.title.isEmpty()
|
||||||
|
@ -745,7 +750,7 @@ void ReceiptCreditsBox(
|
||||||
rpl::single(e.description),
|
rpl::single(e.description),
|
||||||
st::creditsBoxAbout)));
|
st::creditsBoxAbout)));
|
||||||
}
|
}
|
||||||
if (e.gift) {
|
if (e.gift || isPrize) {
|
||||||
Ui::AddSkip(content);
|
Ui::AddSkip(content);
|
||||||
const auto arrow = Ui::Text::SingleCustomEmoji(
|
const auto arrow = Ui::Text::SingleCustomEmoji(
|
||||||
session->data().customEmojiManager().registerInternalEmoji(
|
session->data().customEmojiManager().registerInternalEmoji(
|
||||||
|
|
|
@ -457,6 +457,8 @@ Fn<PaintRoundImageCallback(Fn<void()>)> PaintPreviewCallback(
|
||||||
TextWithEntities GenerateEntryName(const Data::CreditsHistoryEntry &entry) {
|
TextWithEntities GenerateEntryName(const Data::CreditsHistoryEntry &entry) {
|
||||||
return (entry.reaction
|
return (entry.reaction
|
||||||
? tr::lng_credits_box_history_entry_reaction_name
|
? tr::lng_credits_box_history_entry_reaction_name
|
||||||
|
: entry.bareGiveawayMsgId
|
||||||
|
? tr::lng_credits_box_history_entry_giveaway_name
|
||||||
: entry.gift
|
: entry.gift
|
||||||
? tr::lng_credits_box_history_entry_gift_name
|
? tr::lng_credits_box_history_entry_gift_name
|
||||||
: (entry.peerType == Data::CreditsHistoryEntry::PeerType::Fragment)
|
: (entry.peerType == Data::CreditsHistoryEntry::PeerType::Fragment)
|
||||||
|
|
Loading…
Add table
Reference in a new issue