mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 13:17:08 +02:00
Replaced style of button to cancel subscription with hyper link.
This commit is contained in:
parent
7518361266
commit
213274e96c
3 changed files with 62 additions and 18 deletions
|
@ -472,4 +472,20 @@ Data::CreditsGiveawayOptions CreditsGiveawayOptions::options() const {
|
||||||
return _options;
|
return _options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditCreditsSubscription(
|
||||||
|
not_null<Main::Session*> session,
|
||||||
|
const QString &id,
|
||||||
|
bool cancel,
|
||||||
|
Fn<void()> done,
|
||||||
|
Fn<void(QString)> fail) {
|
||||||
|
using Flag = MTPpayments_ChangeStarsSubscription::Flag;
|
||||||
|
session->api().request(
|
||||||
|
MTPpayments_ChangeStarsSubscription(
|
||||||
|
MTP_flags(Flag::f_canceled),
|
||||||
|
MTP_inputPeerSelf(),
|
||||||
|
MTP_string(id),
|
||||||
|
MTP_bool(cancel)
|
||||||
|
)).done(done).fail([=](const MTP::Error &e) { fail(e.type()); }).send();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Api
|
} // namespace Api
|
||||||
|
|
|
@ -109,4 +109,11 @@ private:
|
||||||
[[nodiscard]] rpl::producer<not_null<PeerData*>> PremiumPeerBot(
|
[[nodiscard]] rpl::producer<not_null<PeerData*>> PremiumPeerBot(
|
||||||
not_null<Main::Session*> session);
|
not_null<Main::Session*> session);
|
||||||
|
|
||||||
|
void EditCreditsSubscription(
|
||||||
|
not_null<Main::Session*> session,
|
||||||
|
const QString &id,
|
||||||
|
bool cancel,
|
||||||
|
Fn<void()> done,
|
||||||
|
Fn<void(QString)> fail);
|
||||||
|
|
||||||
} // namespace Api
|
} // namespace Api
|
||||||
|
|
|
@ -1285,6 +1285,10 @@ void ReceiptCreditsBox(
|
||||||
if (s) {
|
if (s) {
|
||||||
const auto user = peer ? peer->asUser() : nullptr;
|
const auto user = peer ? peer->asUser() : nullptr;
|
||||||
const auto bot = (user && !user->isSelf()) ? user : nullptr;
|
const auto bot = (user && !user->isSelf()) ? user : nullptr;
|
||||||
|
const auto toCancel = !s.expired && !s.cancelled && !s.cancelledByBot;
|
||||||
|
if (toCancel) {
|
||||||
|
Ui::AddSkip(content);
|
||||||
|
}
|
||||||
Ui::AddSkip(content);
|
Ui::AddSkip(content);
|
||||||
auto label = object_ptr<Ui::FlatLabel>(
|
auto label = object_ptr<Ui::FlatLabel>(
|
||||||
box,
|
box,
|
||||||
|
@ -1292,13 +1296,37 @@ void ReceiptCreditsBox(
|
||||||
? tr::lng_credits_subscription_off_by_bot_about(
|
? tr::lng_credits_subscription_off_by_bot_about(
|
||||||
lt_bot,
|
lt_bot,
|
||||||
rpl::single(bot->name()))
|
rpl::single(bot->name()))
|
||||||
|
: toCancel
|
||||||
|
? tr::lng_credits_subscription_on_button()
|
||||||
: s.cancelled
|
: s.cancelled
|
||||||
? tr::lng_credits_subscription_off_about()
|
? tr::lng_credits_subscription_off_about()
|
||||||
: tr::lng_credits_subscription_on_about(
|
: tr::lng_credits_subscription_on_about(
|
||||||
lt_date,
|
lt_date,
|
||||||
rpl::single(langDayOfMonthFull(s.until.date()))),
|
rpl::single(langDayOfMonthFull(s.until.date()))),
|
||||||
st::creditsBoxAboutDivider);
|
st::creditsBoxAboutDivider);
|
||||||
if (s.cancelled) {
|
if (toCancel) {
|
||||||
|
label->setClickHandlerFilter([=](
|
||||||
|
const auto &,
|
||||||
|
Qt::MouseButton button) {
|
||||||
|
if (button != Qt::LeftButton) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const auto done = [=, weak = Ui::MakeWeak(box)] {
|
||||||
|
if (const auto strong = weak.data()) {
|
||||||
|
strong->closeBox();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const auto fail = [=, s = box->uiShow()](const QString &e) {
|
||||||
|
s->showToast(e);
|
||||||
|
};
|
||||||
|
Api::EditCreditsSubscription(session, s.id, true, done, fail);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
label->setMarkedText(
|
||||||
|
Ui::Text::Link(
|
||||||
|
tr::lng_credits_subscription_on_button(tr::now),
|
||||||
|
u"internal:"_q));
|
||||||
|
} else if (s.cancelled || s.cancelledByBot) {
|
||||||
label->setTextColorOverride(st::menuIconAttentionColor->c);
|
label->setTextColorOverride(st::menuIconAttentionColor->c);
|
||||||
}
|
}
|
||||||
box->addRow(
|
box->addRow(
|
||||||
|
@ -1335,15 +1363,14 @@ void ReceiptCreditsBox(
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto toRenew = (s.cancelled || s.expired)
|
const auto toRenew = (s.cancelled || s.expired)
|
||||||
&& !s.inviteHash.isEmpty();
|
&& (!s.inviteHash.isEmpty()
|
||||||
const auto toCancel = !toRenew && s;
|
|| (base::unixtime::serialize(s.until) > base::unixtime::now()))
|
||||||
|
&& !s.cancelledByBot;
|
||||||
auto confirmText = rpl::conditional(
|
auto confirmText = rpl::conditional(
|
||||||
state->confirmButtonBusy.value(),
|
state->confirmButtonBusy.value(),
|
||||||
rpl::single(QString()),
|
rpl::single(QString()),
|
||||||
(toRenew
|
(toRenew
|
||||||
? tr::lng_credits_subscription_off_button()
|
? tr::lng_credits_subscription_off_button()
|
||||||
: toCancel
|
|
||||||
? tr::lng_credits_subscription_on_button()
|
|
||||||
: (canConvert || couldConvert || nonConvertible)
|
: (canConvert || couldConvert || nonConvertible)
|
||||||
? (e.savedToProfile
|
? (e.savedToProfile
|
||||||
? tr::lng_gift_display_on_page_hide()
|
? tr::lng_gift_display_on_page_hide()
|
||||||
|
@ -1398,23 +1425,18 @@ void ReceiptCreditsBox(
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
using Flag = MTPpayments_ChangeStarsSubscription::Flag;
|
const auto done = [=] {
|
||||||
session->api().request(
|
|
||||||
MTPpayments_ChangeStarsSubscription(
|
|
||||||
MTP_flags(Flag::f_canceled),
|
|
||||||
MTP_inputPeerSelf(),
|
|
||||||
MTP_string(s.id),
|
|
||||||
MTP_bool(toCancel)
|
|
||||||
)).done([=] {
|
|
||||||
if (const auto strong = weak.data()) {
|
if (const auto strong = weak.data()) {
|
||||||
strong->closeBox();
|
strong->closeBox();
|
||||||
}
|
}
|
||||||
}).fail([=, show = box->uiShow()](const MTP::Error &error) {
|
};
|
||||||
|
const auto fail = [=, show = box->uiShow()](const QString &e) {
|
||||||
if (const auto strong = weak.data()) {
|
if (const auto strong = weak.data()) {
|
||||||
state->confirmButtonBusy = false;
|
state->confirmButtonBusy = false;
|
||||||
}
|
}
|
||||||
show->showToast(error.type());
|
show->showToast(e);
|
||||||
}).send();
|
};
|
||||||
|
Api::EditCreditsSubscription(session, s.id, false, done, fail);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1423,13 +1445,12 @@ void ReceiptCreditsBox(
|
||||||
|| state->convertButtonBusy.current()) {
|
|| state->convertButtonBusy.current()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
state->confirmButtonBusy = true;
|
|
||||||
if (peer
|
if (peer
|
||||||
&& (toRenew
|
&& (toRenew
|
||||||
|| toCancel
|
|
||||||
|| canConvert
|
|| canConvert
|
||||||
|| couldConvert
|
|| couldConvert
|
||||||
|| nonConvertible)) {
|
|| nonConvertible)) {
|
||||||
|
state->confirmButtonBusy = true;
|
||||||
send();
|
send();
|
||||||
} else {
|
} else {
|
||||||
box->closeBox();
|
box->closeBox();
|
||||||
|
|
Loading…
Add table
Reference in a new issue