From 174fb62c325af9904e9f8a1463fe5eb2ee17a9ee Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 22 May 2024 00:49:35 +0300 Subject: [PATCH] Fixed purchases of credits. --- Telegram/SourceFiles/api/api_credits.cpp | 55 +++---------------- Telegram/SourceFiles/data/data_credits.h | 1 + .../SourceFiles/payments/payments_form.cpp | 12 +++- Telegram/SourceFiles/payments/payments_form.h | 1 + .../SourceFiles/settings/settings_credits.cpp | 1 + 5 files changed, 19 insertions(+), 51 deletions(-) diff --git a/Telegram/SourceFiles/api/api_credits.cpp b/Telegram/SourceFiles/api/api_credits.cpp index 32497e2495..717adb64aa 100644 --- a/Telegram/SourceFiles/api/api_credits.cpp +++ b/Telegram/SourceFiles/api/api_credits.cpp @@ -57,7 +57,7 @@ namespace { status.data().vhistory().v ) | ranges::views::transform(HistoryFromTL) | ranges::to_vector, .balance = status.data().vbalance().v, - .allLoaded = status.data().vnext_offset().has_value(), + .allLoaded = !status.data().vnext_offset().has_value(), .token = qs(status.data().vnext_offset().value_or_empty()), }; } @@ -85,6 +85,7 @@ rpl::producer CreditsTopupOptions::request() { option.data().vstore_product().value_or_empty()), .currency = qs(option.data().vcurrency()), .amount = option.data().vamount().v, + .extended = option.data().is_extended(), }; }) | ranges::to_vector; consumer.put_done(); @@ -114,10 +115,6 @@ void CreditsStatus::request( _peer->isSelf() ? MTP_inputPeerSelf() : _peer->input )).done([=](const TLResult &result) { _requestId = 0; -#if _DEBUG - done({ .balance = uint64(base::RandomIndex(9999)) }); - return; -#endif done(StatusFromTL(result, _peer)); }).fail([=] { _requestId = 0; @@ -127,9 +124,11 @@ void CreditsStatus::request( CreditsHistory::CreditsHistory(not_null peer, bool in, bool out) : _peer(peer) -, _flags(HistoryTL::Flags(0) - | (in ? HistoryTL::Flag::f_inbound : HistoryTL::Flags(0)) - | (out ? HistoryTL::Flag::f_outbound : HistoryTL::Flags(0))) +, _flags((in == out) + ? HistoryTL::Flags(0) + : HistoryTL::Flags(0) + | (in ? HistoryTL::Flag::f_inbound : HistoryTL::Flags(0)) + | (out ? HistoryTL::Flag::f_outbound : HistoryTL::Flags(0))) , _api(&peer->session().api().instance()) { } @@ -145,46 +144,6 @@ void CreditsHistory::request( MTP_string(token) )).done([=](const MTPpayments_StarsStatus &result) { _requestId = 0; -#if _DEBUG - done({ - .list = [&] { - auto a = std::vector(); - const auto isIn = _flags & HistoryTL::Flag::f_inbound; - const auto isOut = _flags & HistoryTL::Flag::f_outbound; - for (auto i = 0; i < base::RandomIndex(10) + 1; i++) { - const auto type = (isIn && isOut) - ? base::RandomIndex(4) - : isOut - ? 0 - : (base::RandomIndex(3) + 1); - a.push_back(Data::CreditsHistoryEntry{ - .id = QString::number(base::RandomValue()), - .credits = uint64( - std::max(base::RandomIndex(15000), 1)), - .date = base::unixtime::parse( - std::abs(base::RandomValue())), - .peerType = ((type == 0) - ? Data::CreditsHistoryEntry::PeerType::Peer - : (type == 1) - ? Data::CreditsHistoryEntry::PeerType::PlayMarket - : (type == 2) - ? Data::CreditsHistoryEntry::PeerType::Fragment - : Data::CreditsHistoryEntry::PeerType::AppStore), - .peerId = (type == 0) - ? peerFromUser(5000233800) - : PeerId(0), - }); - } - return a; - }(), - .balance = 47890, - .allLoaded = !token.isEmpty(), - .token = token.isEmpty() - ? QString::number(base::RandomValue()) - : QString(), - }); - return; -#endif done(StatusFromTL(result, _peer)); }).fail([=] { _requestId = 0; diff --git a/Telegram/SourceFiles/data/data_credits.h b/Telegram/SourceFiles/data/data_credits.h index cb0310c939..0984cf8bf4 100644 --- a/Telegram/SourceFiles/data/data_credits.h +++ b/Telegram/SourceFiles/data/data_credits.h @@ -14,6 +14,7 @@ struct CreditTopupOption final { QString product; QString currency; uint64 amount = 0; + bool extended = false; }; using CreditTopupOptions = std::vector; diff --git a/Telegram/SourceFiles/payments/payments_form.cpp b/Telegram/SourceFiles/payments/payments_form.cpp index c02ea408b7..07a6b2a675 100644 --- a/Telegram/SourceFiles/payments/payments_form.cpp +++ b/Telegram/SourceFiles/payments/payments_form.cpp @@ -317,10 +317,16 @@ MTPInputInvoice Form::inputInvoice() const { } else if (const auto slug = std::get_if(&_id.value)) { return MTP_inputInvoiceSlug(MTP_string(slug->slug)); } else if (const auto credits = std::get_if(&_id.value)) { + using Flag = MTPDstarsTopupOption::Flag; + const auto emptyFlag = MTPDstarsTopupOption::Flags(0); return MTP_inputInvoiceStars(MTP_starsTopupOption( - credits->product.isEmpty() - ? MTP_flags(0) - : MTP_flags(MTPDstarsTopupOption::Flag::f_store_product), + MTP_flags(emptyFlag + | (credits->product.isEmpty() + ? Flag::f_store_product + : emptyFlag) + | (credits->extended + ? Flag::f_extended + : emptyFlag)), MTP_long(credits->credits), MTP_string(credits->product), MTP_string(credits->currency), diff --git a/Telegram/SourceFiles/payments/payments_form.h b/Telegram/SourceFiles/payments/payments_form.h index 92448feb6d..8341131159 100644 --- a/Telegram/SourceFiles/payments/payments_form.h +++ b/Telegram/SourceFiles/payments/payments_form.h @@ -223,6 +223,7 @@ struct InvoiceCredits { QString product; QString currency; uint64 amount = 0; + bool extended = false; }; struct InvoiceId { diff --git a/Telegram/SourceFiles/settings/settings_credits.cpp b/Telegram/SourceFiles/settings/settings_credits.cpp index a31c68e10c..71ea3a9e10 100644 --- a/Telegram/SourceFiles/settings/settings_credits.cpp +++ b/Telegram/SourceFiles/settings/settings_credits.cpp @@ -297,6 +297,7 @@ void Credits::setupOptions(not_null container) { .product = option.product, .currency = option.currency, .amount = option.amount, + .extended = option.extended, }; const auto weak = Ui::MakeWeak(button);