mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-03 21:54:05 +02:00
Added description and optional photo to credits receipts.
This commit is contained in:
parent
1edf0ed70b
commit
58da617e3f
5 changed files with 54 additions and 16 deletions
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "apiwrap.h"
|
||||
#include "base/unixtime.h"
|
||||
#include "data/data_peer.h"
|
||||
#include "data/data_photo.h"
|
||||
#include "data/data_session.h"
|
||||
#include "main/main_app_config.h"
|
||||
#include "main/main_session.h"
|
||||
|
@ -21,12 +22,24 @@ namespace Api {
|
|||
namespace {
|
||||
|
||||
[[nodiscard]] Data::CreditsHistoryEntry HistoryFromTL(
|
||||
const MTPStarsTransaction &tl) {
|
||||
const MTPStarsTransaction &tl,
|
||||
not_null<PeerData*> peer) {
|
||||
using HistoryPeerTL = MTPDstarsTransactionPeer;
|
||||
const auto photo = tl.data().vphoto()
|
||||
? peer->owner().photoFromWeb(*tl.data().vphoto(), ImageLocation())
|
||||
: nullptr;
|
||||
return Data::CreditsHistoryEntry{
|
||||
.id = qs(tl.data().vid()),
|
||||
.credits = tl.data().vstars().v,
|
||||
.title = qs(tl.data().vtitle().value_or_empty()),
|
||||
.description = qs(tl.data().vdescription().value_or_empty()),
|
||||
.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,
|
||||
.peerType = tl.data().vpeer().match([](const HistoryPeerTL &) {
|
||||
return Data::CreditsHistoryEntry::PeerType::Peer;
|
||||
}, [](const MTPDstarsTransactionPeerPlayMarket &) {
|
||||
|
@ -40,11 +53,6 @@ namespace {
|
|||
}, [](const MTPDstarsTransactionPeerPremiumBot &) {
|
||||
return Data::CreditsHistoryEntry::PeerType::PremiumBot;
|
||||
}),
|
||||
.bareId = tl.data().vpeer().match([](const HistoryPeerTL &p) {
|
||||
return peerFromMTP(p.vpeer());
|
||||
}, [](const auto &) {
|
||||
return PeerId(0);
|
||||
}).value,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -56,7 +64,9 @@ namespace {
|
|||
return Data::CreditsStatusSlice{
|
||||
.list = ranges::views::all(
|
||||
status.data().vhistory().v
|
||||
) | ranges::views::transform(HistoryFromTL) | ranges::to_vector,
|
||||
) | ranges::views::transform([&](const MTPStarsTransaction &tl) {
|
||||
return HistoryFromTL(tl, peer);
|
||||
}) | ranges::to_vector,
|
||||
.balance = status.data().vbalance().v,
|
||||
.allLoaded = !status.data().vnext_offset().has_value(),
|
||||
.token = qs(status.data().vnext_offset().value_or_empty()),
|
||||
|
|
|
@ -20,6 +20,7 @@ struct CreditTopupOption final {
|
|||
using CreditTopupOptions = std::vector<CreditTopupOption>;
|
||||
|
||||
struct CreditsHistoryEntry final {
|
||||
using PhotoId = uint64;
|
||||
enum class PeerType {
|
||||
Peer,
|
||||
AppStore,
|
||||
|
@ -29,10 +30,13 @@ struct CreditsHistoryEntry final {
|
|||
PremiumBot,
|
||||
};
|
||||
QString id;
|
||||
uint64 credits = 0;
|
||||
QString title;
|
||||
QString description;
|
||||
QDateTime date;
|
||||
PeerType peerType;
|
||||
PhotoId photoId = 0;
|
||||
uint64 credits = 0;
|
||||
uint64 bareId = 0;
|
||||
PeerType peerType;
|
||||
};
|
||||
|
||||
struct CreditsStatusSlice final {
|
||||
|
|
|
@ -96,8 +96,8 @@ giveawayGiftCodeValue: FlatLabel(defaultFlatLabel) {
|
|||
}
|
||||
}
|
||||
giveawayGiftCodeValueMultiline: FlatLabel(giveawayGiftCodeValue) {
|
||||
minWidth: 100px;
|
||||
maxHeight: 0px;
|
||||
minWidth: 128px;
|
||||
maxHeight: 100px;
|
||||
}
|
||||
giveawayGiftCodeValueMargin: margins(13px, 9px, 13px, 9px);
|
||||
giveawayGiftCodePeerMargin: margins(11px, 6px, 11px, 4px);
|
||||
|
|
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "base/unixtime.h"
|
||||
#include "boxes/send_credits_box.h"
|
||||
#include "data/data_credits.h"
|
||||
#include "data/data_photo.h"
|
||||
#include "history/history_item.h"
|
||||
#include "history/history_item_components.h"
|
||||
#include "payments/payments_checkout_process.h" // NonPanelPaymentForm.
|
||||
|
@ -45,10 +46,13 @@ Fn<void(NonPanelPaymentForm)> ProcessNonPanelPaymentFormFactory(
|
|||
const auto receipt = *r;
|
||||
const auto entry = Data::CreditsHistoryEntry{
|
||||
.id = receipt->id,
|
||||
.credits = receipt->credits,
|
||||
.title = receipt->title,
|
||||
.description = receipt->description,
|
||||
.date = base::unixtime::parse(receipt->date),
|
||||
.peerType = Data::CreditsHistoryEntry::PeerType::Peer,
|
||||
.photoId = receipt->photo ? receipt->photo->id : 0,
|
||||
.credits = receipt->credits,
|
||||
.bareId = receipt->peerId.value,
|
||||
.peerType = Data::CreditsHistoryEntry::PeerType::Peer,
|
||||
};
|
||||
controller->uiShow()->show(Box(
|
||||
Settings::ReceiptCreditsBox,
|
||||
|
|
|
@ -764,7 +764,14 @@ void ReceiptCreditsBox(
|
|||
: e.bareId
|
||||
? controller->session().data().peer(PeerId(e.bareId)).get()
|
||||
: nullptr;
|
||||
if (peer) {
|
||||
const auto photo = e.photoId
|
||||
? controller->session().data().photo(e.photoId).get()
|
||||
: nullptr;
|
||||
if (photo) {
|
||||
content->add(object_ptr<Ui::CenterWrap<>>(
|
||||
content,
|
||||
HistoryEntryPhoto(content, photo, stUser.photoSize)));
|
||||
} else if (peer) {
|
||||
content->add(object_ptr<Ui::CenterWrap<>>(
|
||||
content,
|
||||
object_ptr<Ui::UserpicButton>(content, peer, stUser)));
|
||||
|
@ -792,7 +799,10 @@ void ReceiptCreditsBox(
|
|||
box,
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
box,
|
||||
rpl::single(peer
|
||||
rpl::single(
|
||||
!e.title.isEmpty()
|
||||
? e.title
|
||||
: peer
|
||||
? peer->name()
|
||||
: Ui::GenerateEntryName(e).text),
|
||||
st::creditsBoxAboutTitle)));
|
||||
|
@ -838,6 +848,16 @@ void ReceiptCreditsBox(
|
|||
}, amount->lifetime());
|
||||
}
|
||||
|
||||
if (!e.description.isEmpty()) {
|
||||
Ui::AddSkip(content);
|
||||
box->addRow(object_ptr<Ui::CenterWrap<>>(
|
||||
box,
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
box,
|
||||
rpl::single(e.description),
|
||||
st::defaultFlatLabel)));
|
||||
}
|
||||
|
||||
Ui::AddSkip(content);
|
||||
Ui::AddSkip(content);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue