mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Handled subscriptions list changes in settings section for credits.
This commit is contained in:
parent
4608ffcab4
commit
f795d56b2a
3 changed files with 62 additions and 13 deletions
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "api/api_chat_invite.h"
|
||||
|
||||
#include "apiwrap.h"
|
||||
#include "api/api_credits.h"
|
||||
#include "boxes/premium_limits_box.h"
|
||||
#include "core/application.h"
|
||||
#include "data/components/credits.h"
|
||||
|
@ -295,20 +296,39 @@ void ConfirmSubscriptionBox(
|
|||
const auto buttonWidth = state->saveButton
|
||||
? state->saveButton->width()
|
||||
: 0;
|
||||
const auto finish = [=] {
|
||||
state->api = std::nullopt;
|
||||
state->loading.force_assign(false);
|
||||
if (const auto strong = weak.data()) {
|
||||
strong->closeBox();
|
||||
}
|
||||
};
|
||||
state->api->request(
|
||||
MTPpayments_SendStarsForm(
|
||||
MTP_long(formId),
|
||||
MTP_inputInvoiceChatInviteSubscription(MTP_string(hash)))
|
||||
).done([=](const MTPpayments_PaymentResult &result) {
|
||||
state->api = std::nullopt;
|
||||
state->loading.force_assign(false);
|
||||
result.match([&](const MTPDpayments_paymentResult &data) {
|
||||
session->api().applyUpdates(data.vupdates());
|
||||
}, [](const MTPDpayments_paymentVerificationNeeded &data) {
|
||||
});
|
||||
if (weak) {
|
||||
box->closeBox();
|
||||
const auto refill = session->data().activeCreditsSubsRebuilder();
|
||||
const auto strong = weak.data();
|
||||
if (!strong) {
|
||||
return;
|
||||
}
|
||||
if (!refill) {
|
||||
return finish();
|
||||
}
|
||||
const auto api
|
||||
= strong->lifetime().make_state<Api::CreditsHistory>(
|
||||
session->user(),
|
||||
true,
|
||||
true);
|
||||
api->requestSubscriptions({}, [=](Data::CreditsStatusSlice d) {
|
||||
refill->fire(std::move(d));
|
||||
finish();
|
||||
});
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
const auto id = error.type();
|
||||
if (weak) {
|
||||
|
|
|
@ -191,6 +191,19 @@ void Credits::setupSubscriptions(not_null<Ui::VerticalLayout*> container) {
|
|||
fill(std::move(d));
|
||||
});
|
||||
}
|
||||
{
|
||||
using Rebuilder = Data::Session::CreditsSubsRebuilder;
|
||||
using RebuilderPtr = std::shared_ptr<Rebuilder>;
|
||||
const auto rebuilder = content->lifetime().make_state<RebuilderPtr>(
|
||||
self->owner().createCreditsSubsRebuilder());
|
||||
rebuilder->get()->events(
|
||||
) | rpl::start_with_next([=](Data::CreditsStatusSlice slice) {
|
||||
while (content->count()) {
|
||||
delete content->widgetAt(0);
|
||||
}
|
||||
fill(std::move(slice));
|
||||
}, content->lifetime());
|
||||
}
|
||||
}
|
||||
|
||||
void Credits::setupHistory(not_null<Ui::VerticalLayout*> container) {
|
||||
|
|
|
@ -802,6 +802,28 @@ void BoostCreditsBox(
|
|||
}, button->lifetime());
|
||||
}
|
||||
|
||||
void ProcessReceivedSubscriptions(
|
||||
QPointer<Ui::GenericBox> weak,
|
||||
not_null<Main::Session*> session) {
|
||||
const auto rebuilder = session->data().activeCreditsSubsRebuilder();
|
||||
if (const auto strong = weak.data()) {
|
||||
if (!rebuilder) {
|
||||
return strong->closeBox();
|
||||
}
|
||||
const auto api
|
||||
= strong->lifetime().make_state<Api::CreditsHistory>(
|
||||
session->user(),
|
||||
true,
|
||||
true);
|
||||
api->requestSubscriptions({}, [=](Data::CreditsStatusSlice first) {
|
||||
rebuilder->fire(std::move(first));
|
||||
if (const auto strong = weak.data()) {
|
||||
strong->closeBox();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ReceiptCreditsBox(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
not_null<Window::SessionController*> controller,
|
||||
|
@ -1328,9 +1350,7 @@ void ReceiptCreditsBox(
|
|||
return false;
|
||||
}
|
||||
const auto done = [=, weak = Ui::MakeWeak(box)] {
|
||||
if (const auto strong = weak.data()) {
|
||||
strong->closeBox();
|
||||
}
|
||||
ProcessReceivedSubscriptions(weak, session);
|
||||
};
|
||||
const auto fail = [=, s = box->uiShow()](const QString &e) {
|
||||
s->showToast(e);
|
||||
|
@ -1414,15 +1434,11 @@ void ReceiptCreditsBox(
|
|||
}
|
||||
} else if (toRenew && s.expired) {
|
||||
Api::CheckChatInvite(controller, s.inviteHash, nullptr, [=] {
|
||||
if (const auto strong = weak.data()) {
|
||||
strong->closeBox();
|
||||
}
|
||||
ProcessReceivedSubscriptions(weak, session);
|
||||
});
|
||||
} else {
|
||||
const auto done = [=] {
|
||||
if (const auto strong = weak.data()) {
|
||||
strong->closeBox();
|
||||
}
|
||||
ProcessReceivedSubscriptions(weak, session);
|
||||
};
|
||||
const auto fail = [=, show = box->uiShow()](const QString &e) {
|
||||
if (const auto strong = weak.data()) {
|
||||
|
|
Loading…
Add table
Reference in a new issue