mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Added support for credits in messages of prize in giveaways.
This commit is contained in:
parent
202c81b2e5
commit
5b146217c0
6 changed files with 98 additions and 20 deletions
|
@ -2831,6 +2831,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_prize_title" = "Congratulations!";
|
||||
"lng_prize_about" = "You won a prize in a giveaway organized by {channel}.";
|
||||
"lng_prize_duration" = "Your prize is a **Telegram Premium** subscription {duration}.";
|
||||
"lng_prize_credits" = "Your prize is {amount}.";
|
||||
"lng_prize_credits_amount#one" = "{count} Star";
|
||||
"lng_prize_credits_amount#other" = "{count} Stars";
|
||||
"lng_prize_gift_about" = "You've received a gift from {channel}.";
|
||||
"lng_prize_gift_duration" = "Your gift is a **Telegram Premium** subscription {duration}.";
|
||||
"lng_prize_open" = "Open Gift Link";
|
||||
|
|
|
@ -1727,6 +1727,13 @@ void AddCreditsHistoryEntryTable(
|
|||
tr::lng_credits_box_history_entry_via_premium_bot(
|
||||
Ui::Text::RichLangValue));
|
||||
}
|
||||
if (entry.bareGiveawayMsgId) {
|
||||
AddTableRow(
|
||||
table,
|
||||
tr::lng_gift_link_label_to(),
|
||||
controller,
|
||||
controller->session().userId());
|
||||
}
|
||||
if (entry.bareGiveawayMsgId && entry.credits) {
|
||||
AddTableRow(
|
||||
table,
|
||||
|
|
|
@ -129,13 +129,14 @@ struct GiveawayResults {
|
|||
|
||||
enum class GiftType : uchar {
|
||||
Premium, // count - months
|
||||
Stars, // count - stars
|
||||
Credits, // count - credits
|
||||
};
|
||||
|
||||
struct GiftCode {
|
||||
QString slug;
|
||||
ChannelData *channel = nullptr;
|
||||
int count = 0;
|
||||
int giveawayMsgId = 0;
|
||||
GiftType type = GiftType::Premium;
|
||||
bool viaGiveaway = false;
|
||||
bool unclaimed = false;
|
||||
|
|
|
@ -5237,7 +5237,16 @@ void HistoryItem::setServiceMessageByAction(const MTPmessageAction &action) {
|
|||
auto prepareGiftPrize = [&](
|
||||
const MTPDmessageActionPrizeStars &action) {
|
||||
auto result = PreparedServiceText();
|
||||
AssertIsDebug();
|
||||
_history->session().giftBoxStickersPacks().load();
|
||||
result.text = {
|
||||
(action.is_unclaimed()
|
||||
? tr::lng_prize_unclaimed_about
|
||||
: tr::lng_prize_about)(
|
||||
tr::now,
|
||||
lt_channel,
|
||||
_from->owner().peer(
|
||||
peerFromMTP(action.vboost_peer()))->name()),
|
||||
};
|
||||
return result;
|
||||
};
|
||||
|
||||
|
@ -5382,8 +5391,22 @@ void HistoryItem::applyAction(const MTPMessageAction &action) {
|
|||
_media = std::make_unique<Data::MediaGiftBox>(
|
||||
this,
|
||||
_from,
|
||||
Data::GiftType::Stars,
|
||||
Data::GiftType::Credits,
|
||||
data.vstars().v);
|
||||
}, [&](const MTPDmessageActionPrizeStars &data) {
|
||||
_media = std::make_unique<Data::MediaGiftBox>(
|
||||
this,
|
||||
_from,
|
||||
Data::GiftCode{
|
||||
.slug = qs(data.vtransaction_id()),
|
||||
.channel = history()->owner().channel(
|
||||
peerToChannel(peerFromMTP(data.vboost_peer()))),
|
||||
.count = int(data.vstars().v),
|
||||
.giveawayMsgId = data.vgiveaway_msg_id().v,
|
||||
.type = Data::GiftType::Credits,
|
||||
.viaGiveaway = true,
|
||||
.unclaimed = data.is_unclaimed(),
|
||||
});
|
||||
}, [](const auto &) {
|
||||
});
|
||||
}
|
||||
|
|
|
@ -7,11 +7,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "history/view/media/history_view_premium_gift.h"
|
||||
|
||||
#include "base/unixtime.h"
|
||||
#include "boxes/gift_premium_box.h" // ResolveGiftCode
|
||||
#include "chat_helpers/stickers_gift_box_pack.h"
|
||||
#include "core/click_handler_types.h" // ClickHandlerContext
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "data/data_credits.h"
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_user.h"
|
||||
#include "history/history.h"
|
||||
#include "history/history_item.h"
|
||||
|
@ -19,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "lang/lang_keys.h"
|
||||
#include "main/main_session.h"
|
||||
#include "settings/settings_credits.h" // Settings::CreditsId
|
||||
#include "settings/settings_credits_graphics.h"
|
||||
#include "settings/settings_credits_graphics.h" // GiftedCreditsBox
|
||||
#include "settings/settings_premium.h" // Settings::ShowGiftPremium
|
||||
#include "ui/layers/generic_box.h"
|
||||
|
@ -49,7 +52,9 @@ QSize PremiumGift::size() {
|
|||
}
|
||||
|
||||
QString PremiumGift::title() {
|
||||
if (const auto count = stars()) {
|
||||
if (creditsPrize()) {
|
||||
return tr::lng_prize_title(tr::now);
|
||||
} else if (const auto count = credits()) {
|
||||
return tr::lng_gift_stars_title(tr::now, lt_count, count);
|
||||
}
|
||||
return gift()
|
||||
|
@ -60,7 +65,8 @@ QString PremiumGift::title() {
|
|||
}
|
||||
|
||||
TextWithEntities PremiumGift::subtitle() {
|
||||
if (const auto count = stars()) {
|
||||
const auto isCreditsPrize = creditsPrize();
|
||||
if (const auto count = credits(); count && !isCreditsPrize) {
|
||||
return outgoingGift()
|
||||
? tr::lng_gift_stars_outgoing(
|
||||
tr::now,
|
||||
|
@ -82,20 +88,32 @@ TextWithEntities PremiumGift::subtitle() {
|
|||
Ui::Text::Bold(name),
|
||||
Ui::Text::RichLangValue);
|
||||
result.append("\n\n");
|
||||
result.append((_data.unclaimed
|
||||
? tr::lng_prize_unclaimed_duration
|
||||
: _data.viaGiveaway
|
||||
? tr::lng_prize_duration
|
||||
: tr::lng_prize_gift_duration)(
|
||||
result.append(isCreditsPrize
|
||||
? tr::lng_prize_credits(
|
||||
tr::now,
|
||||
lt_duration,
|
||||
Ui::Text::Bold(GiftDuration(_data.count)),
|
||||
Ui::Text::RichLangValue));
|
||||
lt_amount,
|
||||
tr::lng_prize_credits_amount(
|
||||
tr::now,
|
||||
lt_count,
|
||||
credits(),
|
||||
Ui::Text::RichLangValue),
|
||||
Ui::Text::RichLangValue)
|
||||
: (_data.unclaimed
|
||||
? tr::lng_prize_unclaimed_duration
|
||||
: _data.viaGiveaway
|
||||
? tr::lng_prize_duration
|
||||
: tr::lng_prize_gift_duration)(
|
||||
tr::now,
|
||||
lt_duration,
|
||||
Ui::Text::Bold(GiftDuration(_data.count)),
|
||||
Ui::Text::RichLangValue));
|
||||
return result;
|
||||
}
|
||||
|
||||
rpl::producer<QString> PremiumGift::button() {
|
||||
return (gift() && (outgoingGift() || !_data.unclaimed))
|
||||
return creditsPrize()
|
||||
? tr::lng_view_button_giftcode()
|
||||
: (gift() && (outgoingGift() || !_data.unclaimed))
|
||||
? tr::lng_sticker_premium_view()
|
||||
: tr::lng_prize_open();
|
||||
}
|
||||
|
@ -110,7 +128,26 @@ ClickHandlerPtr PremiumGift::createViewLink() {
|
|||
if (const auto controller = my.sessionWindow.get()) {
|
||||
const auto selfId = controller->session().userPeerId();
|
||||
const auto sent = (from->id == selfId);
|
||||
if (data.type == Data::GiftType::Stars) {
|
||||
if (creditsPrize()) {
|
||||
using Type = Data::CreditsHistoryEntry::PeerType;
|
||||
controller->show(Box(
|
||||
Settings::ReceiptCreditsBox,
|
||||
controller,
|
||||
Data::CreditsHistoryEntry{
|
||||
.id = data.slug,
|
||||
.title = QString(),
|
||||
.description = QString(),
|
||||
.date = base::unixtime::parse(date),
|
||||
.credits = uint64(data.count),
|
||||
.barePeerId = data.channel
|
||||
? data.channel->id.value
|
||||
: 0,
|
||||
.bareGiveawayMsgId = uint64(data.giveawayMsgId),
|
||||
.peerType = Type::Peer,
|
||||
.in = true,
|
||||
},
|
||||
Data::SubscriptionEntry()));
|
||||
} else if (data.type == Data::GiftType::Credits) {
|
||||
const auto to = sent ? peer : peer->session().user();
|
||||
controller->show(Box(
|
||||
Settings::GiftedCreditsBox,
|
||||
|
@ -186,8 +223,14 @@ bool PremiumGift::gift() const {
|
|||
return _data.slug.isEmpty() || !_data.channel;
|
||||
}
|
||||
|
||||
int PremiumGift::stars() const {
|
||||
return (_data.type == Data::GiftType::Stars) ? _data.count : 0;
|
||||
bool PremiumGift::creditsPrize() const {
|
||||
return _data.viaGiveaway
|
||||
&& (_data.type == Data::GiftType::Credits)
|
||||
&& !_data.slug.isEmpty();
|
||||
}
|
||||
|
||||
int PremiumGift::credits() const {
|
||||
return (_data.type == Data::GiftType::Credits) ? _data.count : 0;
|
||||
}
|
||||
|
||||
void PremiumGift::ensureStickerCreated() const {
|
||||
|
@ -196,7 +239,7 @@ void PremiumGift::ensureStickerCreated() const {
|
|||
}
|
||||
const auto &session = _parent->history()->session();
|
||||
auto &packs = session.giftBoxStickersPacks();
|
||||
const auto count = stars();
|
||||
const auto count = credits();
|
||||
const auto months = count ? packs.monthsForStars(count) : _data.count;
|
||||
if (const auto document = packs.lookup(months)) {
|
||||
if (const auto sticker = document->sticker()) {
|
||||
|
|
|
@ -49,7 +49,8 @@ private:
|
|||
[[nodiscard]] bool incomingGift() const;
|
||||
[[nodiscard]] bool outgoingGift() const;
|
||||
[[nodiscard]] bool gift() const;
|
||||
[[nodiscard]] int stars() const;
|
||||
[[nodiscard]] bool creditsPrize() const;
|
||||
[[nodiscard]] int credits() const;
|
||||
void ensureStickerCreated() const;
|
||||
|
||||
const not_null<Element*> _parent;
|
||||
|
|
Loading…
Add table
Reference in a new issue