2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Update API scheme to layer 183. Paid media.

This commit is contained in:
John Preston
2024-06-18 14:02:05 +04:00
parent e71a067f4b
commit 3ece9b1566
25 changed files with 227 additions and 533 deletions

View File

@@ -666,6 +666,28 @@ Invoice ParseInvoice(const MTPDmessageMediaInvoice &data) {
return result;
}
PaidMedia ParsePaidMedia(
ParseMediaContext &context,
const MTPDmessageMediaPaidMedia &data,
const QString &folder,
TimeId date) {
auto result = PaidMedia();
result.stars = data.vstars_amount().v;
result.extended.reserve(data.vextended_media().v.size());
for (const auto &extended : data.vextended_media().v) {
result.extended.push_back(extended.match([](
const MTPDmessageExtendedMediaPreview &)
-> std::unique_ptr<Media> {
return std::unique_ptr<Media>();
}, [&](const MTPDmessageExtendedMedia &data)
-> std::unique_ptr<Media> {
return std::make_unique<Media>(
ParseMedia(context, data.vmedia(), folder, date));
}));
}
return result;
}
Poll ParsePoll(const MTPDmessageMediaPoll &data) {
auto result = Poll();
data.vpoll().match([&](const MTPDpoll &poll) {
@@ -1225,6 +1247,8 @@ Media ParseMedia(
result.content = ParseGiveaway(data);
}, [&](const MTPDmessageMediaGiveawayResults &data) {
// #TODO export giveaway
}, [&](const MTPDmessageMediaPaidMedia &data) {
result.content = ParsePaidMedia(context, data, folder, date);
}, [](const MTPDmessageMediaEmpty &data) {});
return result;
}

View File

@@ -182,6 +182,18 @@ struct Invoice {
int32 receiptMsgId = 0;
};
struct Media;
struct PaidMedia {
PaidMedia() = default;
PaidMedia(PaidMedia &&) = default;
PaidMedia &operator=(PaidMedia &&) = default;
PaidMedia(const PaidMedia &) = delete;
PaidMedia &operator=(const PaidMedia &) = delete;
uint64 stars = 0;
std::vector<std::unique_ptr<Media>> extended;
};
struct Poll {
struct Answer {
Utf8String text;
@@ -337,6 +349,7 @@ struct Media {
Invoice,
Poll,
GiveawayStart,
PaidMedia,
UnsupportedMedia> content;
TimeId ttl = 0;

View File

@@ -2092,6 +2092,9 @@ MediaData HtmlWriter::Wrap::prepareMediaData(
result.status = Data::FormatMoneyAmount(data.amount, data.currency);
}, [](const Poll &data) {
}, [](const GiveawayStart &data) {
}, [&](const PaidMedia &data) {
result.classes = "media_invoice";
result.status = Data::FormatMoneyAmount(data.stars, "XTR");
}, [](const UnsupportedMedia &data) {
Unexpected("Unsupported message.");
}, [](v::null_t) {});

View File

@@ -779,6 +779,8 @@ QByteArray SerializeMessage(
{ "until_date", SerializeDate(data.untilDate) },
{ "channels", serialized },
}));
}, [&](const PaidMedia &data) {
push("paid_stars_amount", data.stars);
}, [](const UnsupportedMedia &data) {
Unexpected("Unsupported message.");
}, [](v::null_t) {});