diff --git a/Telegram/SourceFiles/api/api_chat_invite.cpp b/Telegram/SourceFiles/api/api_chat_invite.cpp index 0a53c61dd..134e3a005 100644 --- a/Telegram/SourceFiles/api/api_chat_invite.cpp +++ b/Telegram/SourceFiles/api/api_chat_invite.cpp @@ -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( + 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) { diff --git a/Telegram/SourceFiles/settings/settings_credits.cpp b/Telegram/SourceFiles/settings/settings_credits.cpp index b4cd7396d..f22b94a7c 100644 --- a/Telegram/SourceFiles/settings/settings_credits.cpp +++ b/Telegram/SourceFiles/settings/settings_credits.cpp @@ -191,6 +191,19 @@ void Credits::setupSubscriptions(not_null container) { fill(std::move(d)); }); } + { + using Rebuilder = Data::Session::CreditsSubsRebuilder; + using RebuilderPtr = std::shared_ptr; + const auto rebuilder = content->lifetime().make_state( + 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 container) { diff --git a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp index 299f0437b..0b701307b 100644 --- a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp +++ b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp @@ -802,6 +802,28 @@ void BoostCreditsBox( }, button->lifetime()); } +void ProcessReceivedSubscriptions( + QPointer weak, + not_null 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( + 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 box, not_null 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()) {