mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 15:17:07 +02:00
Support non-convertible star gifts from bots.
This commit is contained in:
parent
d0911b6a45
commit
3cfbd6a93b
13 changed files with 63 additions and 43 deletions
Telegram
Resources/langs
SourceFiles
api
boxes
data
history
info/statistics
settings
ui/effects
|
@ -1879,6 +1879,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_action_gift_got_stars_text#one" = "Display this gift on your page or convert it to **{count}** Star.";
|
||||
"lng_action_gift_got_stars_text#other" = "Display this gift on your page or convert it to **{count}** Stars.";
|
||||
"lng_action_gift_got_gift_text" = "You can keep this gift on your page.";
|
||||
"lng_action_gift_can_remove_text" = "You can remove this gift from your page.";
|
||||
"lng_action_gift_sent_subtitle" = "Gift for {user}";
|
||||
"lng_action_gift_sent_text#one" = "{user} can display this gift on their page or convert it to {count} Star.";
|
||||
"lng_action_gift_sent_text#other" = "{user} can display this gift on their page or convert it to {count} Stars.";
|
||||
|
|
|
@ -117,11 +117,12 @@ constexpr auto kTransactionsLimit = 100;
|
|||
? base::unixtime::parse(tl.data().vtransaction_date()->v)
|
||||
: QDateTime(),
|
||||
.successLink = qs(tl.data().vtransaction_url().value_or_empty()),
|
||||
.convertStars = int(stargift
|
||||
.starsConverted = int(stargift
|
||||
? stargift->data().vconvert_stars().v
|
||||
: 0),
|
||||
.floodSkip = int(tl.data().vfloodskip_number().value_or(0)),
|
||||
.converted = stargift && incoming,
|
||||
.stargift = stargift.has_value(),
|
||||
.reaction = tl.data().is_reaction(),
|
||||
.refunded = tl.data().is_refund(),
|
||||
.pending = tl.data().is_pending(),
|
||||
|
|
|
@ -772,7 +772,7 @@ std::optional<StarGift> FromTL(
|
|||
return StarGift{
|
||||
.id = uint64(data.vid().v),
|
||||
.stars = int64(data.vstars().v),
|
||||
.convertStars = int64(data.vconvert_stars().v),
|
||||
.starsConverted = int64(data.vconvert_stars().v),
|
||||
.document = document,
|
||||
.limitedLeft = remaining.value_or_empty(),
|
||||
.limitedCount = total.value_or_empty(),
|
||||
|
@ -800,7 +800,7 @@ std::optional<UserStarGift> FromTL(
|
|||
data.vmessage()->data().ventities().v),
|
||||
}
|
||||
: TextWithEntities()),
|
||||
.convertStars = int64(data.vconvert_stars().value_or_empty()),
|
||||
.starsConverted = int64(data.vconvert_stars().value_or_empty()),
|
||||
.fromId = (data.vfrom_id()
|
||||
? peerFromUser(data.vfrom_id()->v)
|
||||
: PeerId()),
|
||||
|
|
|
@ -76,7 +76,7 @@ struct GiftOptionData {
|
|||
struct StarGift {
|
||||
uint64 id = 0;
|
||||
int64 stars = 0;
|
||||
int64 convertStars = 0;
|
||||
int64 starsConverted = 0;
|
||||
not_null<DocumentData*> document;
|
||||
int limitedLeft = 0;
|
||||
int limitedCount = 0;
|
||||
|
@ -91,7 +91,7 @@ struct StarGift {
|
|||
struct UserStarGift {
|
||||
StarGift info;
|
||||
TextWithEntities message;
|
||||
int64 convertStars = 0;
|
||||
int64 starsConverted = 0;
|
||||
PeerId fromId = 0;
|
||||
MsgId messageId = 0;
|
||||
TimeId date = 0;
|
||||
|
|
|
@ -266,7 +266,7 @@ object_ptr<Ui::RpWidget> MakeStarGiftStarsValue(
|
|||
raw,
|
||||
tr::lng_gift_sell_small(
|
||||
lt_count_decimal,
|
||||
rpl::single(entry.convertStars * 1.)),
|
||||
rpl::single(entry.starsConverted * 1.)),
|
||||
st::starGiftSmallButton)
|
||||
: nullptr;
|
||||
if (convert) {
|
||||
|
@ -1044,7 +1044,8 @@ void AddStarGiftTable(
|
|||
const auto peerId = PeerId(entry.barePeerId);
|
||||
const auto session = &controller->session();
|
||||
if (peerId) {
|
||||
const auto withSendButton = entry.in;
|
||||
const auto user = session->data().peer(peerId)->asUser();
|
||||
const auto withSendButton = entry.in && user && !user->isBot();
|
||||
AddTableRow(
|
||||
table,
|
||||
tr::lng_credits_box_history_entry_peer_in(),
|
||||
|
@ -1144,12 +1145,17 @@ void AddCreditsHistoryEntryTable(
|
|||
st::giveawayGiftCodeTable),
|
||||
st::giveawayGiftCodeTableMargin);
|
||||
const auto peerId = PeerId(entry.barePeerId);
|
||||
const auto actorId = PeerId(entry.bareActorId);
|
||||
const auto session = &controller->session();
|
||||
if (peerId) {
|
||||
if (actorId || peerId) {
|
||||
auto text = entry.in
|
||||
? tr::lng_credits_box_history_entry_peer_in()
|
||||
: tr::lng_credits_box_history_entry_peer();
|
||||
AddTableRow(table, std::move(text), controller, peerId);
|
||||
AddTableRow(
|
||||
table,
|
||||
std::move(text),
|
||||
controller,
|
||||
actorId ? actorId : peerId);
|
||||
}
|
||||
if (const auto msgId = MsgId(peerId ? entry.bareMsgId : 0)) {
|
||||
const auto peer = session->data().peer(peerId);
|
||||
|
|
|
@ -216,7 +216,7 @@ auto GenerateGiftMedia(
|
|||
return tr::lng_action_gift_got_stars_text(
|
||||
tr::now,
|
||||
lt_count,
|
||||
gift.info.convertStars,
|
||||
gift.info.starsConverted,
|
||||
Ui::Text::RichLangValue);
|
||||
});
|
||||
auto description = data.text.empty()
|
||||
|
|
|
@ -69,19 +69,20 @@ struct CreditsHistoryEntry final {
|
|||
QString successLink;
|
||||
int limitedCount = 0;
|
||||
int limitedLeft = 0;
|
||||
int convertStars = 0;
|
||||
int starsConverted = 0;
|
||||
int floodSkip = 0;
|
||||
bool converted = false;
|
||||
bool anonymous = false;
|
||||
bool savedToProfile = false;
|
||||
bool fromGiftsList = false;
|
||||
bool soldOutInfo = false;
|
||||
bool reaction = false;
|
||||
bool refunded = false;
|
||||
bool pending = false;
|
||||
bool failed = false;
|
||||
bool in = false;
|
||||
bool gift = false;
|
||||
bool converted : 1 = false;
|
||||
bool anonymous : 1 = false;
|
||||
bool stargift : 1 = false;
|
||||
bool savedToProfile : 1 = false;
|
||||
bool fromGiftsList : 1 = false;
|
||||
bool soldOutInfo : 1 = false;
|
||||
bool reaction : 1 = false;
|
||||
bool refunded : 1 = false;
|
||||
bool pending : 1 = false;
|
||||
bool failed : 1 = false;
|
||||
bool in : 1 = false;
|
||||
bool gift : 1 = false;
|
||||
};
|
||||
|
||||
struct CreditsStatusSlice final {
|
||||
|
|
|
@ -139,7 +139,7 @@ struct GiftCode {
|
|||
TextWithEntities message;
|
||||
ChannelData *channel = nullptr;
|
||||
MsgId giveawayMsgId = 0;
|
||||
int convertStars = 0;
|
||||
int starsConverted = 0;
|
||||
int limitedCount = 0;
|
||||
int limitedLeft = 0;
|
||||
int count = 0;
|
||||
|
|
|
@ -5530,7 +5530,7 @@ void HistoryItem::applyAction(const MTPMessageAction &action) {
|
|||
data.vmessage()->data().ventities().v),
|
||||
}
|
||||
: TextWithEntities()),
|
||||
.convertStars = int(data.vconvert_stars().value_or_empty()),
|
||||
.starsConverted = int(data.vconvert_stars().value_or_empty()),
|
||||
.limitedCount = gift.vavailability_total().value_or_empty(),
|
||||
.limitedLeft = gift.vavailability_remains().value_or_empty(),
|
||||
.count = int(gift.vstars().v),
|
||||
|
|
|
@ -80,7 +80,7 @@ TextWithEntities PremiumGift::subtitle() {
|
|||
? tr::lng_action_gift_sent_text(
|
||||
tr::now,
|
||||
lt_count,
|
||||
_data.convertStars,
|
||||
_data.starsConverted,
|
||||
lt_user,
|
||||
Ui::Text::Bold(_parent->history()->peer->shortName()),
|
||||
Ui::Text::RichLangValue)
|
||||
|
@ -89,7 +89,7 @@ TextWithEntities PremiumGift::subtitle() {
|
|||
: tr::lng_action_gift_got_stars_text)(
|
||||
tr::now,
|
||||
lt_count,
|
||||
_data.convertStars,
|
||||
_data.starsConverted,
|
||||
Ui::Text::RichLangValue);
|
||||
}
|
||||
const auto isCreditsPrize = creditsPrize();
|
||||
|
|
|
@ -822,9 +822,7 @@ void CreditsRow::init() {
|
|||
const auto name = !isSpecial
|
||||
? PeerListRow::generateName()
|
||||
: Ui::GenerateEntryName(_entry).text;
|
||||
_name = (_entry.reaction
|
||||
|| _entry.bareGiveawayMsgId
|
||||
|| _entry.convertStars)
|
||||
_name = (_entry.reaction || _entry.stargift || _entry.bareGiveawayMsgId)
|
||||
? Ui::GenerateEntryName(_entry).text
|
||||
: _entry.title.isEmpty()
|
||||
? name
|
||||
|
@ -876,7 +874,7 @@ void CreditsRow::init() {
|
|||
_context);
|
||||
}
|
||||
if (!_paintUserpicCallback) {
|
||||
_paintUserpicCallback = _entry.convertStars
|
||||
_paintUserpicCallback = _entry.stargift
|
||||
? Ui::GenerateGiftStickerUserpicCallback(
|
||||
_context.session,
|
||||
_entry.bareGiftStickerId,
|
||||
|
|
|
@ -797,7 +797,7 @@ void ReceiptCreditsBox(
|
|||
const Data::SubscriptionEntry &s) {
|
||||
const auto item = controller->session().data().message(
|
||||
PeerId(e.barePeerId), MsgId(e.bareMsgId));
|
||||
const auto isStarGift = (e.convertStars > 0) || e.soldOutInfo;
|
||||
const auto isStarGift = e.stargift || e.soldOutInfo;
|
||||
const auto creditsHistoryStarGift = isStarGift && !e.id.isEmpty();
|
||||
const auto sentStarGift = creditsHistoryStarGift && !e.in;
|
||||
const auto convertedStarGift = creditsHistoryStarGift && e.converted;
|
||||
|
@ -811,9 +811,13 @@ void ReceiptCreditsBox(
|
|||
+ controller->session().appConfig().stargiftConvertPeriodMax();
|
||||
const auto timeLeft = int64(convertLast) - int64(base::unixtime::now());
|
||||
const auto timeExceeded = (timeLeft <= 0);
|
||||
const auto forConvert = gotStarGift && !e.converted && starGiftSender;
|
||||
const auto forConvert = gotStarGift
|
||||
&& e.starsConverted
|
||||
&& !e.converted
|
||||
&& starGiftSender;
|
||||
const auto canConvert = forConvert && !timeExceeded;
|
||||
const auto couldConvert = forConvert && timeExceeded;
|
||||
const auto nonConvertible = (gotStarGift && !e.starsConverted);
|
||||
|
||||
box->setStyle(st::giveawayGiftCodeBox);
|
||||
box->setNoContentMargin(true);
|
||||
|
@ -1108,15 +1112,17 @@ void ReceiptCreditsBox(
|
|||
box,
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
box,
|
||||
(couldConvert
|
||||
? tr::lng_action_gift_got_gift_text(
|
||||
Ui::Text::WithEntities)
|
||||
((couldConvert || nonConvertible)
|
||||
? (e.savedToProfile
|
||||
? tr::lng_action_gift_can_remove_text
|
||||
: tr::lng_action_gift_got_gift_text)(
|
||||
Ui::Text::WithEntities)
|
||||
: rpl::combine(
|
||||
(canConvert
|
||||
? tr::lng_action_gift_got_stars_text
|
||||
: tr::lng_gift_got_stars)(
|
||||
lt_count,
|
||||
rpl::single(e.convertStars * 1.),
|
||||
rpl::single(e.starsConverted * 1.),
|
||||
Ui::Text::RichLangValue),
|
||||
tr::lng_paid_about_link()
|
||||
) | rpl::map([](
|
||||
|
@ -1180,7 +1186,7 @@ void ReceiptCreditsBox(
|
|||
|
||||
if (isStarGift && e.id.isEmpty()) {
|
||||
const auto convert = [=, weak = Ui::MakeWeak(box)] {
|
||||
const auto stars = e.convertStars;
|
||||
const auto stars = e.starsConverted;
|
||||
const auto days = canConvert ? ((timeLeft + 86399) / 86400) : 0;
|
||||
const auto name = starGiftSender->shortName();
|
||||
ConfirmConvertStarGift(box->uiShow(), name, stars, days, [=] {
|
||||
|
@ -1319,13 +1325,13 @@ void ReceiptCreditsBox(
|
|||
? tr::lng_credits_subscription_off_button()
|
||||
: toCancel
|
||||
? tr::lng_credits_subscription_on_button()
|
||||
: (canConvert || couldConvert)
|
||||
: (canConvert || couldConvert || nonConvertible)
|
||||
? (e.savedToProfile
|
||||
? tr::lng_gift_display_on_page_hide()
|
||||
: tr::lng_gift_display_on_page())
|
||||
: tr::lng_box_ok()));
|
||||
const auto send = [=, weak = Ui::MakeWeak(box)] {
|
||||
if (canConvert || couldConvert) {
|
||||
if (canConvert || couldConvert || nonConvertible) {
|
||||
const auto save = !e.savedToProfile;
|
||||
const auto window = weakWindow.get();
|
||||
const auto showSection = !e.fromGiftsList;
|
||||
|
@ -1399,7 +1405,12 @@ void ReceiptCreditsBox(
|
|||
return;
|
||||
}
|
||||
state->confirmButtonBusy = true;
|
||||
if ((toRenew || toCancel || canConvert || couldConvert) && peer) {
|
||||
if (peer
|
||||
&& (toRenew
|
||||
|| toCancel
|
||||
|| canConvert
|
||||
|| couldConvert
|
||||
|| nonConvertible)) {
|
||||
send();
|
||||
} else {
|
||||
box->closeBox();
|
||||
|
@ -1491,9 +1502,10 @@ void UserStarGiftBox(
|
|||
.peerType = Data::CreditsHistoryEntry::PeerType::Peer,
|
||||
.limitedCount = data.info.limitedCount,
|
||||
.limitedLeft = data.info.limitedLeft,
|
||||
.convertStars = int(data.info.convertStars),
|
||||
.starsConverted = int(data.info.starsConverted),
|
||||
.converted = false,
|
||||
.anonymous = data.anonymous,
|
||||
.stargift = true,
|
||||
.savedToProfile = !data.hidden,
|
||||
.fromGiftsList = true,
|
||||
.in = data.mine,
|
||||
|
@ -1521,9 +1533,10 @@ void StarGiftViewBox(
|
|||
.peerType = Data::CreditsHistoryEntry::PeerType::Peer,
|
||||
.limitedCount = data.limitedCount,
|
||||
.limitedLeft = data.limitedLeft,
|
||||
.convertStars = data.convertStars,
|
||||
.starsConverted = data.starsConverted,
|
||||
.converted = data.converted,
|
||||
.anonymous = data.anonymous,
|
||||
.stargift = true,
|
||||
.savedToProfile = data.saved,
|
||||
.in = true,
|
||||
.gift = true,
|
||||
|
|
|
@ -553,7 +553,7 @@ TextWithEntities GenerateEntryName(const Data::CreditsHistoryEntry &entry) {
|
|||
? tr::lng_credits_box_history_entry_giveaway_name
|
||||
: entry.converted
|
||||
? tr::lng_credits_box_history_entry_gift_converted
|
||||
: entry.convertStars
|
||||
: entry.starsConverted
|
||||
? tr::lng_credits_box_history_entry_gift_sent
|
||||
: entry.gift
|
||||
? tr::lng_credits_box_history_entry_gift_name
|
||||
|
|
Loading…
Add table
Reference in a new issue