mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Improve gift convert confirmation.
This commit is contained in:
parent
36de2b6ca6
commit
9166acbbb9
4 changed files with 60 additions and 22 deletions
|
@ -1871,6 +1871,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_action_gift_got_subtitle" = "Gift from {user}";
|
"lng_action_gift_got_subtitle" = "Gift from {user}";
|
||||||
"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#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_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_sent_subtitle" = "Gift for {user}";
|
"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#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.";
|
"lng_action_gift_sent_text#other" = "{user} can display this gift on their page or convert it to {count} Stars.";
|
||||||
|
@ -3051,8 +3052,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_gift_convert_to_stars#one" = "Convert to {count} Star";
|
"lng_gift_convert_to_stars#one" = "Convert to {count} Star";
|
||||||
"lng_gift_convert_to_stars#other" = "Convert to {count} Stars";
|
"lng_gift_convert_to_stars#other" = "Convert to {count} Stars";
|
||||||
"lng_gift_convert_sure_title" = "Convert Gift to Stars";
|
"lng_gift_convert_sure_title" = "Convert Gift to Stars";
|
||||||
"lng_gift_convert_sure_text#one" = "Do you want to convert this gift from {user} to **{count} Star**?\n\nThis action cannot be undone.";
|
"lng_gift_convert_sure_confirm#one" = "Do you want to convert this gift from {user} to **{count} Star**?";
|
||||||
"lng_gift_convert_sure_text#other" = "Do you want to convert this gift from {user} to **{count} Stars**?\n\nThis action cannot be undone.";
|
"lng_gift_convert_sure_confirm#other" = "Do you want to convert this gift from {user} to **{count} Stars**?";
|
||||||
|
"lng_gift_convert_sure_limit#one" = "Conversion is available for the next **{count} day**.";
|
||||||
|
"lng_gift_convert_sure_limit#other" = "Conversion is available for the next **{count} days**.";
|
||||||
|
"lng_gift_convert_sure_caution" = "This action cannot be undone. This will permanently destroy the gift.";
|
||||||
"lng_gift_convert_sure" = "Convert";
|
"lng_gift_convert_sure" = "Convert";
|
||||||
"lng_gift_display_done" = "The gift is now shown on your profile page.";
|
"lng_gift_display_done" = "The gift is now shown on your profile page.";
|
||||||
"lng_gift_display_done_hide" = "The gift is now hidden from your profile page.";
|
"lng_gift_display_done_hide" = "The gift is now hidden from your profile page.";
|
||||||
|
|
|
@ -42,6 +42,12 @@ int AppConfig::quoteLengthMax() const {
|
||||||
return get<int>(u"quote_length_max"_q, 1024);
|
return get<int>(u"quote_length_max"_q, 1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AppConfig::stargiftConvertPeriodMax() const {
|
||||||
|
return get<int>(
|
||||||
|
u"stargifts_convert_period_max"_q,
|
||||||
|
_account->mtp().isTestMode() ? 300 : (90 * 86400));
|
||||||
|
}
|
||||||
|
|
||||||
void AppConfig::refresh(bool force) {
|
void AppConfig::refresh(bool force) {
|
||||||
if (_requestId || !_api) {
|
if (_requestId || !_api) {
|
||||||
if (force) {
|
if (force) {
|
||||||
|
|
|
@ -64,6 +64,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] int quoteLengthMax() const;
|
[[nodiscard]] int quoteLengthMax() const;
|
||||||
|
[[nodiscard]] int stargiftConvertPeriodMax() const;
|
||||||
|
|
||||||
void refresh(bool force = false);
|
void refresh(bool force = false);
|
||||||
|
|
||||||
|
|
|
@ -174,17 +174,17 @@ void ToggleStarGiftSaved(
|
||||||
sender->inputUser,
|
sender->inputUser,
|
||||||
MTP_int(itemId.bare)
|
MTP_int(itemId.bare)
|
||||||
)).done([=] {
|
)).done([=] {
|
||||||
|
done(true);
|
||||||
if (const auto strong = weak.get()) {
|
if (const auto strong = weak.get()) {
|
||||||
strong->showToast((save
|
strong->showToast((save
|
||||||
? tr::lng_gift_display_done
|
? tr::lng_gift_display_done
|
||||||
: tr::lng_gift_display_done_hide)(tr::now));
|
: tr::lng_gift_display_done_hide)(tr::now));
|
||||||
}
|
}
|
||||||
done(true);
|
|
||||||
}).fail([=](const MTP::Error &error) {
|
}).fail([=](const MTP::Error &error) {
|
||||||
|
done(false);
|
||||||
if (const auto strong = weak.get()) {
|
if (const auto strong = weak.get()) {
|
||||||
strong->showToast(error.type());
|
strong->showToast(error.type());
|
||||||
}
|
}
|
||||||
done(false);
|
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,14 +192,28 @@ void ConfirmConvertStarGift(
|
||||||
std::shared_ptr<Ui::Show> show,
|
std::shared_ptr<Ui::Show> show,
|
||||||
QString name,
|
QString name,
|
||||||
int stars,
|
int stars,
|
||||||
|
int daysLeft,
|
||||||
Fn<void()> convert) {
|
Fn<void()> convert) {
|
||||||
show->show(Ui::MakeConfirmBox({
|
auto text = rpl::combine(
|
||||||
.text = tr::lng_gift_convert_sure_text(
|
tr::lng_gift_convert_sure_confirm(
|
||||||
lt_count,
|
lt_count,
|
||||||
rpl::single(stars * 1.),
|
rpl::single(stars * 1.),
|
||||||
lt_user,
|
lt_user,
|
||||||
rpl::single(Ui::Text::Bold(name)),
|
rpl::single(Ui::Text::Bold(name)),
|
||||||
Ui::Text::RichLangValue),
|
Ui::Text::RichLangValue),
|
||||||
|
tr::lng_gift_convert_sure_limit(
|
||||||
|
lt_count,
|
||||||
|
rpl::single(daysLeft * 1.),
|
||||||
|
Ui::Text::RichLangValue),
|
||||||
|
tr::lng_gift_convert_sure_caution(Ui::Text::RichLangValue)
|
||||||
|
) | rpl::map([](
|
||||||
|
TextWithEntities &&a,
|
||||||
|
TextWithEntities &&b,
|
||||||
|
TextWithEntities &&c) {
|
||||||
|
return a.append("\n\n").append(b).append("\n\n").append(c);
|
||||||
|
});
|
||||||
|
show->show(Ui::MakeConfirmBox({
|
||||||
|
.text = std::move(text),
|
||||||
.confirmed = [=](Fn<void()> close) { close(); convert(); },
|
.confirmed = [=](Fn<void()> close) { close(); convert(); },
|
||||||
.confirmText = tr::lng_gift_convert_sure(),
|
.confirmText = tr::lng_gift_convert_sure(),
|
||||||
.title = tr::lng_gift_convert_sure_title(),
|
.title = tr::lng_gift_convert_sure_title(),
|
||||||
|
@ -741,7 +755,13 @@ void ReceiptCreditsBox(
|
||||||
: (isStarGift && e.in)
|
: (isStarGift && e.in)
|
||||||
? controller->session().data().peer(PeerId(e.barePeerId))->asUser()
|
? controller->session().data().peer(PeerId(e.barePeerId))->asUser()
|
||||||
: nullptr;
|
: nullptr;
|
||||||
const auto canConvert = gotStarGift && !e.converted && starGiftSender;
|
const auto convertLast = base::unixtime::serialize(e.date)
|
||||||
|
+ 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 canConvert = forConvert && !timeExceeded;
|
||||||
|
const auto couldConvert = forConvert && timeExceeded;
|
||||||
|
|
||||||
box->setStyle(st::giveawayGiftCodeBox);
|
box->setStyle(st::giveawayGiftCodeBox);
|
||||||
box->setNoContentMargin(true);
|
box->setNoContentMargin(true);
|
||||||
|
@ -1034,17 +1054,23 @@ void ReceiptCreditsBox(
|
||||||
box,
|
box,
|
||||||
object_ptr<Ui::FlatLabel>(
|
object_ptr<Ui::FlatLabel>(
|
||||||
box,
|
box,
|
||||||
rpl::combine(
|
(couldConvert
|
||||||
(canConvert
|
? tr::lng_action_gift_got_gift_text(
|
||||||
? tr::lng_action_gift_got_stars_text
|
Ui::Text::WithEntities)
|
||||||
: tr::lng_gift_got_stars)(
|
: rpl::combine(
|
||||||
lt_count,
|
(canConvert
|
||||||
rpl::single(e.convertStars * 1.),
|
? tr::lng_action_gift_got_stars_text
|
||||||
Ui::Text::RichLangValue),
|
: tr::lng_gift_got_stars)(
|
||||||
tr::lng_paid_about_link()
|
lt_count,
|
||||||
) | rpl::map([](TextWithEntities text, QString link) {
|
rpl::single(e.convertStars * 1.),
|
||||||
return text.append(' ').append(Ui::Text::Link(link));
|
Ui::Text::RichLangValue),
|
||||||
}),
|
tr::lng_paid_about_link()
|
||||||
|
) | rpl::map([](
|
||||||
|
TextWithEntities text,
|
||||||
|
QString link) {
|
||||||
|
return text.append(' ').append(
|
||||||
|
Ui::Text::Link(link));
|
||||||
|
})),
|
||||||
st::creditsBoxAbout)))->entity();
|
st::creditsBoxAbout)))->entity();
|
||||||
about->setClickHandlerFilter([=](const auto &...) {
|
about->setClickHandlerFilter([=](const auto &...) {
|
||||||
Core::App().iv().openWithIvPreferred(
|
Core::App().iv().openWithIvPreferred(
|
||||||
|
@ -1101,8 +1127,9 @@ void ReceiptCreditsBox(
|
||||||
if (isStarGift && e.id.isEmpty()) {
|
if (isStarGift && e.id.isEmpty()) {
|
||||||
const auto convert = [=, weak = Ui::MakeWeak(box)] {
|
const auto convert = [=, weak = Ui::MakeWeak(box)] {
|
||||||
const auto stars = e.convertStars;
|
const auto stars = e.convertStars;
|
||||||
|
const auto days = canConvert ? ((timeLeft + 86399) / 86400) : 0;
|
||||||
const auto name = starGiftSender->shortName();
|
const auto name = starGiftSender->shortName();
|
||||||
ConfirmConvertStarGift(box->uiShow(), name, stars, [=] {
|
ConfirmConvertStarGift(box->uiShow(), name, stars, days, [=] {
|
||||||
if (state->convertButtonBusy.current()
|
if (state->convertButtonBusy.current()
|
||||||
|| state->confirmButtonBusy.current()) {
|
|| state->confirmButtonBusy.current()) {
|
||||||
return;
|
return;
|
||||||
|
@ -1235,13 +1262,13 @@ void ReceiptCreditsBox(
|
||||||
? tr::lng_credits_subscription_off_button()
|
? tr::lng_credits_subscription_off_button()
|
||||||
: toCancel
|
: toCancel
|
||||||
? tr::lng_credits_subscription_on_button()
|
? tr::lng_credits_subscription_on_button()
|
||||||
: canConvert
|
: (canConvert || couldConvert)
|
||||||
? (e.savedToProfile
|
? (e.savedToProfile
|
||||||
? tr::lng_gift_display_on_page_hide()
|
? tr::lng_gift_display_on_page_hide()
|
||||||
: tr::lng_gift_display_on_page())
|
: tr::lng_gift_display_on_page())
|
||||||
: tr::lng_box_ok()));
|
: tr::lng_box_ok()));
|
||||||
const auto send = [=, weak = Ui::MakeWeak(box)] {
|
const auto send = [=, weak = Ui::MakeWeak(box)] {
|
||||||
if (canConvert) {
|
if (canConvert || couldConvert) {
|
||||||
const auto save = !e.savedToProfile;
|
const auto save = !e.savedToProfile;
|
||||||
const auto window = weakWindow.get();
|
const auto window = weakWindow.get();
|
||||||
const auto showSection = !e.fromGiftsList;
|
const auto showSection = !e.fromGiftsList;
|
||||||
|
@ -1315,7 +1342,7 @@ void ReceiptCreditsBox(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
state->confirmButtonBusy = true;
|
state->confirmButtonBusy = true;
|
||||||
if ((toRenew || toCancel || canConvert) && peer) {
|
if ((toRenew || toCancel || canConvert || couldConvert) && peer) {
|
||||||
send();
|
send();
|
||||||
} else {
|
} else {
|
||||||
box->closeBox();
|
box->closeBox();
|
||||||
|
|
Loading…
Add table
Reference in a new issue