mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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_title" = "Congratulations!";
|
||||||
"lng_prize_about" = "You won a prize in a giveaway organized by {channel}.";
|
"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_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_about" = "You've received a gift from {channel}.";
|
||||||
"lng_prize_gift_duration" = "Your gift is a **Telegram Premium** subscription {duration}.";
|
"lng_prize_gift_duration" = "Your gift is a **Telegram Premium** subscription {duration}.";
|
||||||
"lng_prize_open" = "Open Gift Link";
|
"lng_prize_open" = "Open Gift Link";
|
||||||
|
|
|
@ -1727,6 +1727,13 @@ 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) {
|
||||||
|
AddTableRow(
|
||||||
|
table,
|
||||||
|
tr::lng_gift_link_label_to(),
|
||||||
|
controller,
|
||||||
|
controller->session().userId());
|
||||||
|
}
|
||||||
if (entry.bareGiveawayMsgId && entry.credits) {
|
if (entry.bareGiveawayMsgId && entry.credits) {
|
||||||
AddTableRow(
|
AddTableRow(
|
||||||
table,
|
table,
|
||||||
|
|
|
@ -129,13 +129,14 @@ struct GiveawayResults {
|
||||||
|
|
||||||
enum class GiftType : uchar {
|
enum class GiftType : uchar {
|
||||||
Premium, // count - months
|
Premium, // count - months
|
||||||
Stars, // count - stars
|
Credits, // count - credits
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GiftCode {
|
struct GiftCode {
|
||||||
QString slug;
|
QString slug;
|
||||||
ChannelData *channel = nullptr;
|
ChannelData *channel = nullptr;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
int giveawayMsgId = 0;
|
||||||
GiftType type = GiftType::Premium;
|
GiftType type = GiftType::Premium;
|
||||||
bool viaGiveaway = false;
|
bool viaGiveaway = false;
|
||||||
bool unclaimed = false;
|
bool unclaimed = false;
|
||||||
|
|
|
@ -5237,7 +5237,16 @@ void HistoryItem::setServiceMessageByAction(const MTPmessageAction &action) {
|
||||||
auto prepareGiftPrize = [&](
|
auto prepareGiftPrize = [&](
|
||||||
const MTPDmessageActionPrizeStars &action) {
|
const MTPDmessageActionPrizeStars &action) {
|
||||||
auto result = PreparedServiceText();
|
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;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5382,8 +5391,22 @@ void HistoryItem::applyAction(const MTPMessageAction &action) {
|
||||||
_media = std::make_unique<Data::MediaGiftBox>(
|
_media = std::make_unique<Data::MediaGiftBox>(
|
||||||
this,
|
this,
|
||||||
_from,
|
_from,
|
||||||
Data::GiftType::Stars,
|
Data::GiftType::Credits,
|
||||||
data.vstars().v);
|
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 &) {
|
}, [](const auto &) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,11 +7,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "history/view/media/history_view_premium_gift.h"
|
#include "history/view/media/history_view_premium_gift.h"
|
||||||
|
|
||||||
|
#include "base/unixtime.h"
|
||||||
#include "boxes/gift_premium_box.h" // ResolveGiftCode
|
#include "boxes/gift_premium_box.h" // ResolveGiftCode
|
||||||
#include "chat_helpers/stickers_gift_box_pack.h"
|
#include "chat_helpers/stickers_gift_box_pack.h"
|
||||||
#include "core/click_handler_types.h" // ClickHandlerContext
|
#include "core/click_handler_types.h" // ClickHandlerContext
|
||||||
#include "data/data_document.h"
|
|
||||||
#include "data/data_channel.h"
|
#include "data/data_channel.h"
|
||||||
|
#include "data/data_credits.h"
|
||||||
|
#include "data/data_document.h"
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
#include "history/history_item.h"
|
#include "history/history_item.h"
|
||||||
|
@ -19,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "settings/settings_credits.h" // Settings::CreditsId
|
#include "settings/settings_credits.h" // Settings::CreditsId
|
||||||
|
#include "settings/settings_credits_graphics.h"
|
||||||
#include "settings/settings_credits_graphics.h" // GiftedCreditsBox
|
#include "settings/settings_credits_graphics.h" // GiftedCreditsBox
|
||||||
#include "settings/settings_premium.h" // Settings::ShowGiftPremium
|
#include "settings/settings_premium.h" // Settings::ShowGiftPremium
|
||||||
#include "ui/layers/generic_box.h"
|
#include "ui/layers/generic_box.h"
|
||||||
|
@ -49,7 +52,9 @@ QSize PremiumGift::size() {
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PremiumGift::title() {
|
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 tr::lng_gift_stars_title(tr::now, lt_count, count);
|
||||||
}
|
}
|
||||||
return gift()
|
return gift()
|
||||||
|
@ -60,7 +65,8 @@ QString PremiumGift::title() {
|
||||||
}
|
}
|
||||||
|
|
||||||
TextWithEntities PremiumGift::subtitle() {
|
TextWithEntities PremiumGift::subtitle() {
|
||||||
if (const auto count = stars()) {
|
const auto isCreditsPrize = creditsPrize();
|
||||||
|
if (const auto count = credits(); count && !isCreditsPrize) {
|
||||||
return outgoingGift()
|
return outgoingGift()
|
||||||
? tr::lng_gift_stars_outgoing(
|
? tr::lng_gift_stars_outgoing(
|
||||||
tr::now,
|
tr::now,
|
||||||
|
@ -82,20 +88,32 @@ TextWithEntities PremiumGift::subtitle() {
|
||||||
Ui::Text::Bold(name),
|
Ui::Text::Bold(name),
|
||||||
Ui::Text::RichLangValue);
|
Ui::Text::RichLangValue);
|
||||||
result.append("\n\n");
|
result.append("\n\n");
|
||||||
result.append((_data.unclaimed
|
result.append(isCreditsPrize
|
||||||
? tr::lng_prize_unclaimed_duration
|
? tr::lng_prize_credits(
|
||||||
: _data.viaGiveaway
|
|
||||||
? tr::lng_prize_duration
|
|
||||||
: tr::lng_prize_gift_duration)(
|
|
||||||
tr::now,
|
tr::now,
|
||||||
lt_duration,
|
lt_amount,
|
||||||
Ui::Text::Bold(GiftDuration(_data.count)),
|
tr::lng_prize_credits_amount(
|
||||||
Ui::Text::RichLangValue));
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<QString> PremiumGift::button() {
|
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_sticker_premium_view()
|
||||||
: tr::lng_prize_open();
|
: tr::lng_prize_open();
|
||||||
}
|
}
|
||||||
|
@ -110,7 +128,26 @@ ClickHandlerPtr PremiumGift::createViewLink() {
|
||||||
if (const auto controller = my.sessionWindow.get()) {
|
if (const auto controller = my.sessionWindow.get()) {
|
||||||
const auto selfId = controller->session().userPeerId();
|
const auto selfId = controller->session().userPeerId();
|
||||||
const auto sent = (from->id == selfId);
|
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();
|
const auto to = sent ? peer : peer->session().user();
|
||||||
controller->show(Box(
|
controller->show(Box(
|
||||||
Settings::GiftedCreditsBox,
|
Settings::GiftedCreditsBox,
|
||||||
|
@ -186,8 +223,14 @@ bool PremiumGift::gift() const {
|
||||||
return _data.slug.isEmpty() || !_data.channel;
|
return _data.slug.isEmpty() || !_data.channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PremiumGift::stars() const {
|
bool PremiumGift::creditsPrize() const {
|
||||||
return (_data.type == Data::GiftType::Stars) ? _data.count : 0;
|
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 {
|
void PremiumGift::ensureStickerCreated() const {
|
||||||
|
@ -196,7 +239,7 @@ void PremiumGift::ensureStickerCreated() const {
|
||||||
}
|
}
|
||||||
const auto &session = _parent->history()->session();
|
const auto &session = _parent->history()->session();
|
||||||
auto &packs = session.giftBoxStickersPacks();
|
auto &packs = session.giftBoxStickersPacks();
|
||||||
const auto count = stars();
|
const auto count = credits();
|
||||||
const auto months = count ? packs.monthsForStars(count) : _data.count;
|
const auto months = count ? packs.monthsForStars(count) : _data.count;
|
||||||
if (const auto document = packs.lookup(months)) {
|
if (const auto document = packs.lookup(months)) {
|
||||||
if (const auto sticker = document->sticker()) {
|
if (const auto sticker = document->sticker()) {
|
||||||
|
|
|
@ -49,7 +49,8 @@ private:
|
||||||
[[nodiscard]] bool incomingGift() const;
|
[[nodiscard]] bool incomingGift() const;
|
||||||
[[nodiscard]] bool outgoingGift() const;
|
[[nodiscard]] bool outgoingGift() const;
|
||||||
[[nodiscard]] bool gift() const;
|
[[nodiscard]] bool gift() const;
|
||||||
[[nodiscard]] int stars() const;
|
[[nodiscard]] bool creditsPrize() const;
|
||||||
|
[[nodiscard]] int credits() const;
|
||||||
void ensureStickerCreated() const;
|
void ensureStickerCreated() const;
|
||||||
|
|
||||||
const not_null<Element*> _parent;
|
const not_null<Element*> _parent;
|
||||||
|
|
Loading…
Add table
Reference in a new issue