From 7d115b3fab49f896aaa99d4b46c7c613aa969981 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 21 Jun 2024 02:49:14 +0300 Subject: [PATCH] Improved api support to credit history entries. --- Telegram/SourceFiles/api/api_credits.cpp | 21 ++++++++++++++++----- Telegram/SourceFiles/data/data_credits.h | 6 ++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/api/api_credits.cpp b/Telegram/SourceFiles/api/api_credits.cpp index 13cf45474..4d296286b 100644 --- a/Telegram/SourceFiles/api/api_credits.cpp +++ b/Telegram/SourceFiles/api/api_credits.cpp @@ -30,6 +30,12 @@ constexpr auto kTransactionsLimit = 100; const auto photo = tl.data().vphoto() ? peer->owner().photoFromWeb(*tl.data().vphoto(), ImageLocation()) : nullptr; + const auto barePeerId = tl.data().vpeer().match([]( + const HistoryPeerTL &p) { + return peerFromMTP(p.vpeer()); + }, [](const auto &) { + return PeerId(0); + }).value; return Data::CreditsHistoryEntry{ .id = qs(tl.data().vid()), .title = qs(tl.data().vtitle().value_or_empty()), @@ -37,11 +43,7 @@ constexpr auto kTransactionsLimit = 100; .date = base::unixtime::parse(tl.data().vdate().v), .photoId = photo ? photo->id : 0, .credits = tl.data().vstars().v, - .bareId = tl.data().vpeer().match([](const HistoryPeerTL &p) { - return peerFromMTP(p.vpeer()); - }, [](const auto &) { - return PeerId(0); - }).value, + .bareId = barePeerId, .peerType = tl.data().vpeer().match([](const HistoryPeerTL &) { return Data::CreditsHistoryEntry::PeerType::Peer; }, [](const MTPDstarsTransactionPeerPlayMarket &) { @@ -56,6 +58,15 @@ constexpr auto kTransactionsLimit = 100; return Data::CreditsHistoryEntry::PeerType::PremiumBot; }), .refunded = tl.data().is_refund(), + .pending = tl.data().is_pending(), + .failed = tl.data().is_failed(), + .finishDate = tl.data().vtransaction_date() + ? base::unixtime::parse(tl.data().vtransaction_date()->v) + : QDateTime(), + .finishUrl = qs(tl.data().vtransaction_url().value_or_empty()), + .in = (!barePeerId || tl.data().is_refund()) + && !tl.data().is_pending() + && !tl.data().is_failed(), }; } diff --git a/Telegram/SourceFiles/data/data_credits.h b/Telegram/SourceFiles/data/data_credits.h index ddfd22a83..f013382e8 100644 --- a/Telegram/SourceFiles/data/data_credits.h +++ b/Telegram/SourceFiles/data/data_credits.h @@ -38,6 +38,12 @@ struct CreditsHistoryEntry final { uint64 bareId = 0; PeerType peerType; bool refunded = false; + bool pending = false; + bool failed = false; + QDateTime finishDate; + QString finishUrl; + bool in = false; + }; struct CreditsStatusSlice final {