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