Added ability to cancel and renew subscription from settings section.
This commit is contained in:
parent
32e8ed93e2
commit
4f7364b798
|
@ -342,7 +342,8 @@ void ConfirmSubscriptionBox(
|
||||||
void CheckChatInvite(
|
void CheckChatInvite(
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
const QString &hash,
|
const QString &hash,
|
||||||
ChannelData *invitePeekChannel) {
|
ChannelData *invitePeekChannel,
|
||||||
|
Fn<void()> loaded) {
|
||||||
const auto session = &controller->session();
|
const auto session = &controller->session();
|
||||||
const auto weak = base::make_weak(controller);
|
const auto weak = base::make_weak(controller);
|
||||||
session->api().checkChatInvite(hash, [=](const MTPChatInvite &result) {
|
session->api().checkChatInvite(hash, [=](const MTPChatInvite &result) {
|
||||||
|
@ -350,6 +351,9 @@ void CheckChatInvite(
|
||||||
if (!strong) {
|
if (!strong) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (loaded) {
|
||||||
|
loaded();
|
||||||
|
}
|
||||||
Core::App().hideMediaView();
|
Core::App().hideMediaView();
|
||||||
const auto show = [&](not_null<PeerData*> chat) {
|
const auto show = [&](not_null<PeerData*> chat) {
|
||||||
const auto way = Window::SectionShow::Way::Forward;
|
const auto way = Window::SectionShow::Way::Forward;
|
||||||
|
|
|
@ -38,7 +38,8 @@ namespace Api {
|
||||||
void CheckChatInvite(
|
void CheckChatInvite(
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
const QString &hash,
|
const QString &hash,
|
||||||
ChannelData *invitePeekChannel = nullptr);
|
ChannelData *invitePeekChannel = nullptr,
|
||||||
|
Fn<void()> loaded = nullptr);
|
||||||
|
|
||||||
} // namespace Api
|
} // namespace Api
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "settings/settings_credits_graphics.h"
|
#include "settings/settings_credits_graphics.h"
|
||||||
|
|
||||||
|
#include "api/api_chat_invite.h"
|
||||||
#include "api/api_credits.h"
|
#include "api/api_credits.h"
|
||||||
#include "api/api_earn.h"
|
#include "api/api_earn.h"
|
||||||
|
#include "apiwrap.h"
|
||||||
#include "base/timer_rpl.h"
|
#include "base/timer_rpl.h"
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
#include "boxes/gift_premium_box.h"
|
#include "boxes/gift_premium_box.h"
|
||||||
|
@ -29,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
#include "history/history_item.h"
|
#include "history/history_item.h"
|
||||||
#include "history/history_item_components.h" // HistoryServicePaymentRefund.
|
#include "history/history_item_components.h" // HistoryServicePaymentRefund.
|
||||||
|
#include "info/channel_statistics/boosts/giveaway/boost_badge.h" // InfiniteRadialAnimationWidget.
|
||||||
#include "info/settings/info_settings_widget.h" // SectionCustomTopBarData.
|
#include "info/settings/info_settings_widget.h" // SectionCustomTopBarData.
|
||||||
#include "info/statistics/info_statistics_list_controllers.h"
|
#include "info/statistics/info_statistics_list_controllers.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
|
@ -783,9 +786,68 @@ void ReceiptCreditsBox(
|
||||||
}, widget->lifetime());
|
}, widget->lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto button = box->addButton(tr::lng_box_ok(), [=] {
|
const auto toRenew = (s.cancelled || s.expired)
|
||||||
box->closeBox();
|
&& !s.inviteHash.isEmpty();
|
||||||
|
const auto toCancel = !toRenew && s;
|
||||||
|
struct State final {
|
||||||
|
rpl::variable<bool> confirmButtonBusy;
|
||||||
|
};
|
||||||
|
const auto state = box->lifetime().make_state<State>();
|
||||||
|
auto confirmText = rpl::conditional(
|
||||||
|
state->confirmButtonBusy.value(),
|
||||||
|
rpl::single(QString()),
|
||||||
|
toRenew
|
||||||
|
? tr::lng_credits_subscription_off_button()
|
||||||
|
: toCancel
|
||||||
|
? tr::lng_credits_subscription_on_button()
|
||||||
|
: tr::lng_box_ok());
|
||||||
|
|
||||||
|
using Flag = MTPpayments_ChangeStarsSubscription::Flag;
|
||||||
|
const auto send = [=, weak = Ui::MakeWeak(box)] {
|
||||||
|
if (toRenew && s.expired) {
|
||||||
|
Api::CheckChatInvite(controller, s.inviteHash, nullptr, [=] {
|
||||||
|
if (const auto strong = weak.get()) {
|
||||||
|
strong->closeBox();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
session->api().request(
|
||||||
|
MTPpayments_ChangeStarsSubscription(
|
||||||
|
MTP_flags(Flag::f_canceled),
|
||||||
|
MTP_inputPeerSelf(),
|
||||||
|
MTP_string(s.id),
|
||||||
|
MTP_bool(toCancel)
|
||||||
|
)).done([=] {
|
||||||
|
state->confirmButtonBusy = false;
|
||||||
|
if (const auto strong = weak.get()) {
|
||||||
|
strong->closeBox();
|
||||||
|
}
|
||||||
|
}).fail([=, show = box->uiShow()](const MTP::Error &error) {
|
||||||
|
state->confirmButtonBusy = false;
|
||||||
|
show->showToast(error.type());
|
||||||
|
}).send();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto button = box->addButton(std::move(confirmText), [=] {
|
||||||
|
if (state->confirmButtonBusy.current()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
state->confirmButtonBusy = true;
|
||||||
|
if ((toRenew || toCancel) && peer) {
|
||||||
|
send();
|
||||||
|
} else {
|
||||||
|
box->closeBox();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
{
|
||||||
|
using namespace Info::Statistics;
|
||||||
|
const auto loadingAnimation = InfiniteRadialAnimationWidget(
|
||||||
|
button,
|
||||||
|
button->height() / 2);
|
||||||
|
AddChildToWidgetCenter(button, loadingAnimation);
|
||||||
|
loadingAnimation->showOn(state->confirmButtonBusy.value());
|
||||||
|
}
|
||||||
const auto buttonWidth = st::boxWidth
|
const auto buttonWidth = st::boxWidth
|
||||||
- rect::m::sum::h(st::giveawayGiftCodeBox.buttonPadding);
|
- rect::m::sum::h(st::giveawayGiftCodeBox.buttonPadding);
|
||||||
button->widthValue() | rpl::filter([=] {
|
button->widthValue() | rpl::filter([=] {
|
||||||
|
|
Loading…
Reference in New Issue